From 0c00bef71e586c6b5c601fc47baf33d10ea4f04c Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Thu, 6 Oct 2011 13:07:33 +0000 Subject: [PATCH] HTTPCLIENT-1127: fixed dead-lock between SingleClientConnManager and AbstractPooledConnAdapter git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1179609 13f79535-47bb-0310-9956-ffa450edef68 --- .../impl/conn/AbstractClientConnAdapter.java | 45 +++++++++---------- .../impl/conn/AbstractPooledConnAdapter.java | 2 +- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java b/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java index 802af2489..cfb9af216 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/AbstractClientConnAdapter.java @@ -78,7 +78,7 @@ public abstract class AbstractClientConnAdapter implements ManagedClientConnecti * 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; @@ -114,9 +114,8 @@ public abstract class AbstractClientConnAdapter implements ManagedClientConnecti * 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; } @@ -303,32 +302,32 @@ public abstract class AbstractClientConnAdapter implements ManagedClientConnecti } } - 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) { @@ -338,7 +337,7 @@ public abstract class AbstractClientConnAdapter implements ManagedClientConnecti } } - public synchronized Object removeAttribute(final String id) { + public Object removeAttribute(final String id) { OperatedClientConnection conn = getWrappedConnection(); assertValid(conn); if (conn instanceof HttpContext) { @@ -348,7 +347,7 @@ public abstract class AbstractClientConnAdapter implements ManagedClientConnecti } } - 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) { diff --git a/httpclient/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java b/httpclient/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java index 1fa5de72b..4748ee297 100644 --- a/httpclient/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java +++ b/httpclient/src/main/java/org/apache/http/impl/conn/AbstractPooledConnAdapter.java @@ -105,7 +105,7 @@ public abstract class AbstractPooledConnAdapter extends AbstractClientConnAdapte * This adapter becomes useless. */ @Override - protected synchronized void detach() { + protected void detach() { poolEntry = null; super.detach(); }