hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1730831 - /httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
Date Wed, 17 Feb 2016 13:34:12 GMT
Author: olegk
Date: Wed Feb 17 13:34:12 2016
New Revision: 1730831

URL: http://svn.apache.org/viewvc?rev=1730831&view=rev
Log:
Fixed race condition in request initialization code and #endOfInput method in async client
protocol handlers

Modified:
    httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java

Modified: httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java?rev=1730831&r1=1730830&r2=1730831&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
(original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
Wed Feb 17 13:34:12 2016
@@ -329,27 +329,30 @@ public class HttpAsyncRequestExecutor im
     @Override
     public void endOfInput(final NHttpClientConnection conn) throws IOException {
         final State state = getState(conn);
-        if (state != null) {
-            if (state.getRequestState().compareTo(MessageState.READY) != 0) {
-                state.invalidate();
-            }
-            final HttpAsyncClientExchangeHandler handler = getHandler(conn);
-            if (handler != null) {
-                if (state.isValid()) {
-                    handler.inputTerminated();
-                } else {
-                    handler.failed(new ConnectionClosedException("Connection closed"));
+        final HttpContext context = conn.getContext();
+        synchronized (context) {
+            if (state != null) {
+                if (state.getRequestState().compareTo(MessageState.READY) != 0) {
+                    state.invalidate();
+                }
+                final HttpAsyncClientExchangeHandler handler = getHandler(conn);
+                if (handler != null) {
+                    if (state.isValid()) {
+                        handler.inputTerminated();
+                    } else {
+                        handler.failed(new ConnectionClosedException("Connection closed"));
+                    }
                 }
             }
+            // Closing connection in an orderly manner and
+            // waiting for output buffer to get flushed.
+            // Do not want to wait indefinitely, though, in case
+            // the opposite end is not reading
+            if (conn.getSocketTimeout() <= 0) {
+                conn.setSocketTimeout(1000);
+            }
+            conn.close();
         }
-        // Closing connection in an orderly manner and
-        // waiting for output buffer to get flushed.
-        // Do not want to wait indefinitely, though, in case
-        // the opposite end is not reading
-        if (conn.getSocketTimeout() <= 0) {
-            conn.setSocketTimeout(1000);
-        }
-        conn.close();
     }
 
     @Override
@@ -396,11 +399,11 @@ public class HttpAsyncRequestExecutor im
         this.exceptionLogger.log(ex);
     }
 
-    private State getState(final NHttpConnection conn) {
+    private static State getState(final NHttpConnection conn) {
         return (State) conn.getContext().getAttribute(HTTP_EXCHANGE_STATE);
     }
 
-    private HttpAsyncClientExchangeHandler getHandler(final NHttpConnection conn) {
+    private static HttpAsyncClientExchangeHandler getHandler(final NHttpConnection conn)
{
         return (HttpAsyncClientExchangeHandler) conn.getContext().getAttribute(HTTP_HANDLER);
     }
 



Mime
View raw message