This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push: new 17890c3 Refacfor to (hopefully) aid fixing crash on shutdown 17890c3 is described below commit 17890c3d2696bc634129f746901d7edb3b4dc8aa Author: Mark Thomas <ma...@apache.org> AuthorDate: Wed Sep 25 16:33:25 2019 +0100 Refacfor to (hopefully) aid fixing crash on shutdown Reduce code duplication slightly. Check closed status inside each lock so a) check is closer to the code that uses the socket and b) we have the option of using the lock to help avoid the crash --- java/org/apache/tomcat/util/net/AprEndpoint.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/java/org/apache/tomcat/util/net/AprEndpoint.java b/java/org/apache/tomcat/util/net/AprEndpoint.java index 46c7047..bd7149d 100644 --- a/java/org/apache/tomcat/util/net/AprEndpoint.java +++ b/java/org/apache/tomcat/util/net/AprEndpoint.java @@ -2138,10 +2138,6 @@ public class AprEndpoint extends AbstractEndpoint<Long,Long> implements SNICallB private int fillReadBuffer(boolean block, ByteBuffer to) throws IOException { - if (isClosed()) { - throw new IOException(sm.getString("socket.apr.closed", getSocket())); - } - Lock readLock = getBlockingStatusReadLock(); WriteLock writeLock = getBlockingStatusWriteLock(); @@ -2149,6 +2145,7 @@ public class AprEndpoint extends AbstractEndpoint<Long,Long> implements SNICallB int result = 0; readLock.lock(); try { + checkClosed(); if (getBlockingStatus() == block) { if (block) { Socket.timeoutSet(getSocket().longValue(), getReadTimeout() * 1000); @@ -2164,6 +2161,7 @@ public class AprEndpoint extends AbstractEndpoint<Long,Long> implements SNICallB if (!readDone) { writeLock.lock(); try { + checkClosed(); // Set the current settings for this socket setBlockingStatus(block); if (block) { @@ -2234,6 +2232,13 @@ public class AprEndpoint extends AbstractEndpoint<Long,Long> implements SNICallB } + private void checkClosed() throws IOException { + if (isClosed()) { + throw new IOException(sm.getString("socket.apr.closed", getSocket())); + } + } + + @Override protected void doClose() { if (log.isDebugEnabled()) { @@ -2311,15 +2316,12 @@ public class AprEndpoint extends AbstractEndpoint<Long,Long> implements SNICallB @Override protected void doWrite(boolean block, ByteBuffer from) throws IOException { - if (isClosed()) { - throw new IOException(sm.getString("socket.apr.closed", getSocket())); - } - Lock readLock = getBlockingStatusReadLock(); WriteLock writeLock = getBlockingStatusWriteLock(); readLock.lock(); try { + checkClosed(); if (getBlockingStatus() == block) { if (block) { Socket.timeoutSet(getSocket().longValue(), getWriteTimeout() * 1000); @@ -2333,6 +2335,7 @@ public class AprEndpoint extends AbstractEndpoint<Long,Long> implements SNICallB writeLock.lock(); try { + checkClosed(); // Set the current settings for this socket setBlockingStatus(block); if (block) { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org