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 2009/10/16 14:22:27 UTC

svn commit: r825864 - in /httpcomponents/httpclient/trunk: RELEASE_NOTES.txt httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java

Author: olegk
Date: Fri Oct 16 12:22:27 2009
New Revision: 825864

URL: http://svn.apache.org/viewvc?rev=825864&view=rev
Log:
HTTPCLIENT-881: Fixed race condition in AbstractClientConnAdapter that makes it possible for an aborted connection to be returned to the pool
Contributed by Tim Boemker <tboemker at elynx.com>

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=825864&r1=825863&r2=825864&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Fri Oct 16 12:22:27 2009
@@ -1,6 +1,11 @@
 Changes since 4.0
 -------------------
 
+* [HTTPCLIENT-881] Fixed race condition in AbstractClientConnAdapter that makes it
+  possible for an aborted connection to be returned to the pool.
+  Contributed by Tim Boemker <tboemker at elynx.com> and 
+  Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCLIENT-832] Distinguish cookie format errors from violations of restrictions 
   imposed by a cookie specification. In the latter case 
   CookieRestrictionViolationException will be thrown.

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java?rev=825864&r1=825863&r2=825864&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java Fri Oct 16 12:22:27 2009
@@ -83,8 +83,8 @@
     /** The reusability marker. */
     private volatile boolean markedReusable;
 
-    /** True if the connection has been aborted. */
-    private volatile boolean aborted;
+    /** True if the connection has been shut down or released. */
+    private volatile boolean shutdown;
     
     /** The duration this is valid for while idle (in ms). */
     private volatile long duration;
@@ -104,7 +104,7 @@
         connManager = mgr;
         wrappedConnection = conn;
         markedReusable = false;
-        aborted = false;
+        shutdown = false;
         duration = Long.MAX_VALUE;
     } // <constructor>
 
@@ -133,7 +133,7 @@
      * @throws InterruptedIOException   if the connection has been aborted
      */
     protected final void assertNotAborted() throws InterruptedIOException {
-        if (aborted) {
+        if (shutdown) {
             throw new InterruptedIOException("Connection has been shut down.");
         }
     }
@@ -160,7 +160,7 @@
     }
 
     public boolean isStale() {
-        if (aborted)
+        if (shutdown)
             return true;
         OperatedClientConnection conn = getWrappedConnection();
         if (conn == null)
@@ -316,16 +316,17 @@
     }
 
     public void releaseConnection() {
+        shutdown = true;
         if (connManager != null) {
             connManager.releaseConnection(this, duration, TimeUnit.MILLISECONDS);
         }
     }
 
     public void abortConnection() {
-        if (aborted) {
+        if (shutdown) {
             return;
         }
-        aborted = true;
+        shutdown = true;
         unmarkReusable();
         try {
             shutdown();
@@ -345,7 +346,9 @@
         // manager if #abortConnection() is called from the main execution 
         // thread while there is no blocking I/O operation.
         if (executionThread.equals(Thread.currentThread())) {
-            releaseConnection();
+            if (connManager != null) {
+                connManager.releaseConnection(this, duration, TimeUnit.MILLISECONDS);
+            }
         }
     }