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 2011/10/06 15:08:18 UTC

svn commit: r1179610 - in /httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/impl/conn: AbstractClientConnAdapter.java AbstractPooledConnAdapter.java

Author: olegk
Date: Thu Oct  6 13:08:17 2011
New Revision: 1179610

URL: http://svn.apache.org/viewvc?rev=1179610&view=rev
Log:
HTTPCLIENT-1127: fixed dead-lock between SingleClientConnManager and AbstractPooledConnAdapter

Modified:
    httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java
    httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java

Modified: httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java?rev=1179610&r1=1179609&r2=1179610&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java (original)
+++ httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java Thu Oct  6 13:08:17 2011
@@ -74,7 +74,7 @@ public abstract class AbstractClientConn
      * This attribute MUST NOT be final, so the adapter can be detached
      * from the connection manager without keeping a hard reference there.
      */
-    private volatile ClientConnectionManager connManager;
+    private final ClientConnectionManager connManager;
 
     /** The wrapped connection. */
     private volatile OperatedClientConnection wrappedConnection;
@@ -110,9 +110,8 @@ public abstract class AbstractClientConn
      * Detaches this adapter from the wrapped connection.
      * This adapter becomes useless.
      */
-    protected synchronized void detach() {
+    protected void detach() {
         wrappedConnection = null;
-        connManager = null; // base class attribute
         duration = Long.MAX_VALUE;
     }
 
@@ -299,32 +298,32 @@ public abstract class AbstractClientConn
         }
     }
 
-    public synchronized void releaseConnection() {
-        if (released) {
-            return;
-        }
-        released = true;
-        if (connManager != null) {
+    public void releaseConnection() {
+        synchronized (connManager) {
+            if (released) {
+                return;
+            }
+            released = true;
             connManager.releaseConnection(this, duration, TimeUnit.MILLISECONDS);
         }
     }
 
-    public synchronized void abortConnection() {
-        if (released) {
-            return;
-        }
-        released = true;
-        unmarkReusable();
-        try {
-            shutdown();
-        } catch (IOException ignore) {
-        }
-        if (connManager != null) {
+    public void abortConnection() {
+        synchronized (connManager) {
+            if (released) {
+                return;
+            }
+            released = true;
+            unmarkReusable();
+            try {
+                shutdown();
+            } catch (IOException ignore) {
+            }
             connManager.releaseConnection(this, duration, TimeUnit.MILLISECONDS);
         }
     }
 
-    public synchronized Object getAttribute(final String id) {
+    public Object getAttribute(final String id) {
         OperatedClientConnection conn = getWrappedConnection();
         assertValid(conn);
         if (conn instanceof HttpContext) {
@@ -334,7 +333,7 @@ public abstract class AbstractClientConn
         }
     }
 
-    public synchronized Object removeAttribute(final String id) {
+    public Object removeAttribute(final String id) {
         OperatedClientConnection conn = getWrappedConnection();
         assertValid(conn);
         if (conn instanceof HttpContext) {
@@ -344,7 +343,7 @@ public abstract class AbstractClientConn
         }
     }
 
-    public synchronized void setAttribute(final String id, final Object obj) {
+    public void setAttribute(final String id, final Object obj) {
         OperatedClientConnection conn = getWrappedConnection();
         assertValid(conn);
         if (conn instanceof HttpContext) {

Modified: httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java?rev=1179610&r1=1179609&r2=1179610&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java (original)
+++ httpcomponents/httpclient/branches/4.1.x/httpclient/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java Thu Oct  6 13:08:17 2011
@@ -102,7 +102,7 @@ public abstract class AbstractPooledConn
      * This adapter becomes useless.
      */
     @Override
-    protected synchronized void detach() {
+    protected void detach() {
         poolEntry = null;
         super.detach();
     }