You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2015/10/29 18:01:31 UTC
svn commit: r1711303 -
/tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java
Author: remm
Date: Thu Oct 29 17:01:31 2015
New Revision: 1711303
URL: http://svn.apache.org/viewvc?rev=1711303&view=rev
Log:
After a timeout using a future, the operation that caused the timeout should be cancelled, otherwise it will still be pending. Found it investigating 58565, and could be "causing" 57799 (which would be a timeout on a read being swallowed and then disguised as a pending exception after trying to read again).
Modified:
tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java
Modified: tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java?rev=1711303&r1=1711302&r2=1711303&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Thu Oct 29 17:01:31 2015
@@ -37,6 +37,7 @@ import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
@@ -1151,10 +1152,11 @@ public class Nio2Endpoint extends Abstra
private int fillReadBuffer(boolean block) throws IOException {
socketBufferHandler.configureReadBufferForWrite();
int nRead = 0;
+ Future<Integer> integer = null;
if (block) {
try {
- nRead = getSocket().read(socketBufferHandler.getReadBuffer()).get(
- getNio2ReadTimeout(), TimeUnit.MILLISECONDS).intValue();
+ integer = getSocket().read(socketBufferHandler.getReadBuffer());
+ nRead = integer.get(getNio2ReadTimeout(), TimeUnit.MILLISECONDS).intValue();
// Blocking read so need to release here since there will
// not be a callback to a completion handler.
readPending.release();
@@ -1167,8 +1169,10 @@ public class Nio2Endpoint extends Abstra
} catch (InterruptedException e) {
throw new IOException(e);
} catch (TimeoutException e) {
- SocketTimeoutException ex = new SocketTimeoutException();
- throw ex;
+ if (integer != null) {
+ integer.cancel(true);
+ }
+ throw new SocketTimeoutException();
}
} else {
Nio2Endpoint.startInline();
@@ -1226,11 +1230,12 @@ public class Nio2Endpoint extends Abstra
*/
@Override
protected void doWriteInternal(boolean block) throws IOException {
+ Future<Integer> integer = null;
try {
socketBufferHandler.configureWriteBufferForRead();
do {
- if (getSocket().write(socketBufferHandler.getWriteBuffer()).get(
- getNio2WriteTimeout(), TimeUnit.MILLISECONDS).intValue() < 0) {
+ integer = getSocket().write(socketBufferHandler.getWriteBuffer());
+ if (integer.get(getNio2WriteTimeout(), TimeUnit.MILLISECONDS).intValue() < 0) {
throw new EOFException(sm.getString("iob.failedwrite"));
}
} while (socketBufferHandler.getWriteBuffer().hasRemaining());
@@ -1243,6 +1248,9 @@ public class Nio2Endpoint extends Abstra
} catch (InterruptedException e) {
throw new IOException(e);
} catch (TimeoutException e) {
+ if (integer != null) {
+ integer.cancel(true);
+ }
throw new SocketTimeoutException();
}
}
@@ -1254,7 +1262,6 @@ public class Nio2Endpoint extends Abstra
throw getError();
}
-
// Before doing a blocking flush, make sure that any pending non
// blocking write has completed.
try {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org