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 2015/10/21 10:51:21 UTC
svn commit: r1709768 - in
/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol:
HttpAsyncRequestExecutor.java HttpAsyncRequester.java
Author: olegk
Date: Wed Oct 21 08:51:20 2015
New Revision: 1709768
URL: http://svn.apache.org/viewvc?rev=1709768&view=rev
Log:
Fixed race condition in request initialization code in async client protocol handlers
Modified:
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java?rev=1709768&r1=1709767&r2=1709768&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java Wed Oct 21 08:51:20 2015
@@ -171,10 +171,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/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java?rev=1709768&r1=1709767&r2=1709768&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequester.java Wed Oct 21 08:51:20 2015
@@ -136,16 +136,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();
}
}