hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1709760 - in /httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol: HttpAsyncRequestExecutor.java HttpAsyncRequester.java
Date Wed, 21 Oct 2015 08:48:06 GMT
Author: olegk
Date: Wed Oct 21 08:48:06 2015
New Revision: 1709760

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

Modified:
    httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
    httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.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=1709760&r1=1709759&r2=1709760&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 Oct 21 08:48:06 2015
@@ -170,10 +170,14 @@ public class HttpAsyncRequestExecutor im
             conn.suspendOutput();
             return;
         }
-        final HttpAsyncClientExchangeHandler handler = getHandler(conn);
-        if (handler == null || handler.isDone()) {
-            conn.suspendOutput();
-            return;
+        final HttpContext context = conn.getContext();
+        final HttpAsyncClientExchangeHandler handler;
+        synchronized (context) {
+            handler = getHandler(conn);
+            if (handler == null || handler.isDone()) {
+                conn.suspendOutput();
+                return;
+            }
         }
         final boolean pipelined = handler.getClass().getAnnotation(Pipelined.class) != null;
 

Modified: httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java?rev=1709760&r1=1709759&r2=1709760&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java
(original)
+++ httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java
Wed Oct 21 08:48:06 2015
@@ -150,16 +150,22 @@ public class HttpAsyncRequester {
 
     private void initExection(
             final HttpAsyncClientExchangeHandler handler, final NHttpClientConnection conn)
{
-        conn.getContext().setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, handler);
-        if (!conn.isOpen()) {
-            handler.failed(new ConnectionClosedException("Connection closed"));
+
+        final HttpContext context = conn.getContext();
+        synchronized (context) {
+            context.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, handler);
+            if (!conn.isOpen()) {
+                handler.failed(new ConnectionClosedException("Connection closed"));
+            } else {
+                conn.requestOutput();
+            }
+        }
+        if (handler.isDone()) {
             try {
                 handler.close();
             } catch (final IOException ex) {
                 log(ex);
             }
-        } else {
-            conn.requestOutput();
         }
     }
 



Mime
View raw message