Author: markt
Date: Tue Feb 17 21:02:09 2015
New Revision: 1660498
URL: http://svn.apache.org/r1660498
Log:
Possible fix for occasional NIO2 CI failures. Without the sync it is possible
for a write registration to get lost.
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=1660498&r1=1660497&r2=1660498&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/net/Nio2Endpoint.java Tue Feb 17
21:02:09 2015
@@ -736,7 +736,7 @@ public class Nio2Endpoint extends Abstra
private final CompletionHandler<Integer, ByteBuffer>
writeCompletionHandler;
private final CompletionHandler<Long, ByteBuffer[]>
gatheringWriteCompletionHandler;
- private final Semaphore writePending = new Semaphore(1);
+ private final Semaphore writePending = new Semaphore(1); // Guarded by
writeCompletionHandler
private boolean writeInterest = false; // Guarded by
writeCompletionHandler
private boolean writeNotify = false;
@@ -1199,10 +1199,12 @@ public class Nio2Endpoint extends Abstra
// Before doing a blocking flush, make sure that any pending non
// blocking write has completed.
try {
- if (writePending.tryAcquire(getNio2WriteTimeout(),
TimeUnit.MILLISECONDS)) {
- writePending.release();
- } else {
- throw new SocketTimeoutException();
+ synchronized(writeCompletionHandler) {
+ if (writePending.tryAcquire(getNio2WriteTimeout(),
TimeUnit.MILLISECONDS)) {
+ writePending.release();
+ } else {
+ throw new SocketTimeoutException();
+ }
}
} catch (InterruptedException e) {
// Ignore
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]