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/10/12 14:36:25 UTC
svn commit: r1631168 - in
/httpcomponents/httpasyncclient/trunk/httpasyncclient/src:
main/java/org/apache/http/impl/nio/client/
test/java/org/apache/http/nio/client/integration/
Author: olegk
Date: Sun Oct 12 12:36:25 2014
New Revision: 1631168
URL: http://svn.apache.org/r1631168
Log:
Fixed potential race condition in case of abnormal termination of pipelined message exchange (request producers / response consumers may be not fully closed out)
Modified:
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/AbstractClientExchangeHandler.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/PipeliningClientExchangeHandlerImpl.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPipelining.java
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/AbstractClientExchangeHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/AbstractClientExchangeHandler.java?rev=1631168&r1=1631167&r2=1631168&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/AbstractClientExchangeHandler.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/AbstractClientExchangeHandler.java Sun Oct 12 12:36:25 2014
@@ -402,13 +402,16 @@ abstract class AbstractClientExchangeHan
@Override
public final void failed(final Exception ex) {
- try {
- executionFailed(ex);
- } finally {
+ if (this.closed.compareAndSet(false, true)) {
try {
- this.resultFuture.failed(ex);
+ try {
+ executionFailed(ex);
+ } finally {
+ discardConnection();
+ releaseResources();
+ }
} finally {
- close();
+ this.resultFuture.failed(ex);
}
}
}
@@ -423,11 +426,11 @@ abstract class AbstractClientExchangeHan
try {
return executionCancelled();
} finally {
- this.resultFuture.cancel();
+ discardConnection();
+ releaseResources();
}
} finally {
- discardConnection();
- releaseResources();
+ this.resultFuture.cancel();
}
}
return false;
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/PipeliningClientExchangeHandlerImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/PipeliningClientExchangeHandlerImpl.java?rev=1631168&r1=1631167&r2=1631168&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/PipeliningClientExchangeHandlerImpl.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/client/PipeliningClientExchangeHandlerImpl.java Sun Oct 12 12:36:25 2014
@@ -153,6 +153,9 @@ class PipeliningClientExchangeHandlerImp
if (responseConsumer != null) {
responseConsumer.failed(ex);
}
+ for (final HttpAsyncResponseConsumer<T> cancellable: this.responseConsumerQueue) {
+ cancellable.cancel();
+ }
}
@Override
@@ -296,7 +299,7 @@ class PipeliningClientExchangeHandlerImp
if (result != null) {
this.resultQueue.add(result);
} else {
- this.resultFuture.failed(ex);
+ failed(ex);
}
if (!this.resultFuture.isDone() && this.responseConsumerQueue.isEmpty()) {
this.resultFuture.completed(new ArrayList<T>(this.resultQueue));
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPipelining.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPipelining.java?rev=1631168&r1=1631167&r2=1631168&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPipelining.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestHttpAsyncPipelining.java Sun Oct 12 12:36:25 2014
@@ -216,9 +216,9 @@ public class TestHttpAsyncPipelining ext
Assert.assertNotNull(c1.getResult());
Assert.assertTrue(c2.isDone());
Assert.assertNotNull(c2.getResult());
- Assert.assertFalse(c3.isDone());
+ Assert.assertTrue(c3.isDone());
Assert.assertNull(c3.getResult());
- Assert.assertFalse(c4.isDone());
+ Assert.assertTrue(c4.isDone());
Assert.assertNull(c4.getResult());
}