You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2014/01/31 16:53:32 UTC

svn commit: r1563155 - in /httpcomponents/httpcore/trunk: RELEASE_NOTES.txt httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java

Author: olegk
Date: Fri Jan 31 15:53:32 2014
New Revision: 1563155

URL: http://svn.apache.org/r1563155
Log:
HTTPCORE-370: Race condition if connection request succeeds and times out at the same time

Modified:
    httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java

Modified: httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=1563155&r1=1563154&r2=1563155&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Fri Jan 31 15:53:32 2014
@@ -6,6 +6,9 @@ Changes since release 4.3.1
 
 * [HTTPCORE-358] Added I/O reactor listener backlog parameter.
   Contributed by Dmitry Potapov <potapov.d at gmail.com>
+
+* [HTTPCORE-370] Race condition if connection request succeeds and times out at the same time.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
     
 * [HTTPCORE-357] Avoid DNS lookups in SSLIOSession.
   Contributed by Oleg Kalnichevski <olegk at apache.org>

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java?rev=1563155&r1=1563154&r2=1563155&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/DefaultConnectingIOReactor.java Fri Jan 31 15:53:32 2014
@@ -175,13 +175,26 @@ public class DefaultConnectingIOReactor 
                     sessionRequest.failed(ex);
                 }
                 key.cancel();
-                if (channel.isConnected()) {
+                key.attach(null);
+                if (!sessionRequest.isCompleted()) {
                     addChannel(new ChannelEntry(channel, sessionRequest));
+                } else {
+                    try {
+                        channel.close();
+                    } catch (IOException ignore) {
+                    }
                 }
             }
 
         } catch (final CancelledKeyException ex) {
+            final SessionRequestHandle requestHandle = (SessionRequestHandle) key.attachment();
             key.attach(null);
+            if (requestHandle != null) {
+                final SessionRequestImpl sessionRequest = requestHandle.getSessionRequest();
+                if (sessionRequest != null) {
+                    sessionRequest.cancel();
+                }
+            }
         }
     }