Return-Path: Delivered-To: apmail-hc-dev-archive@www.apache.org Received: (qmail 75037 invoked from network); 15 Oct 2009 21:39:55 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 15 Oct 2009 21:39:55 -0000 Received: (qmail 12752 invoked by uid 500); 15 Oct 2009 21:39:55 -0000 Delivered-To: apmail-hc-dev-archive@hc.apache.org Received: (qmail 12679 invoked by uid 500); 15 Oct 2009 21:39:55 -0000 Mailing-List: contact dev-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list dev@hc.apache.org Received: (qmail 12552 invoked by uid 99); 15 Oct 2009 21:39:55 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Oct 2009 21:39:55 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Oct 2009 21:39:52 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 4AE5F234C045 for ; Thu, 15 Oct 2009 14:39:31 -0700 (PDT) Message-ID: <602222984.1255642771301.JavaMail.jira@brutus> Date: Thu, 15 Oct 2009 14:39:31 -0700 (PDT) From: "Tim Boemker (JIRA)" To: dev@hc.apache.org Subject: [jira] Updated: (HTTPCLIENT-881) AbstractClientConnAdapter doesn't ensure that only one of ConnectionReleaseTrigger.abortConnection, .releaseConnection has effect In-Reply-To: <1071092458.1255633891370.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/HTTPCLIENT-881?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Tim Boemker updated HTTPCLIENT-881: ----------------------------------- Attachment: HTTPCLIENT-881.patch Also attached. Index: AbstractClientConnAdapter.java =================================================================== --- AbstractClientConnAdapter.java (revision 825665) +++ AbstractClientConnAdapter.java (working copy) @@ -86,6 +86,9 @@ /** True if the connection has been aborted. */ private volatile boolean aborted; + /** True if the connection has been released. */ + private boolean released; + /** The duration this is valid for while idle (in ms). */ private volatile long duration; @@ -316,16 +319,25 @@ } public void releaseConnection() { + synchronized(this) { + if (aborted || released) { + return; + } + released = true; + } if (connManager != null) { connManager.releaseConnection(this, duration, TimeUnit.MILLISECONDS); } } + public void abortConnection() { - if (aborted) { - return; + synchronized(this) { + if (aborted || released) { + return; + } + aborted = true; } - aborted = true; unmarkReusable(); try { shutdown(); > AbstractClientConnAdapter doesn't ensure that only one of ConnectionReleaseTrigger.abortConnection, .releaseConnection has effect > --------------------------------------------------------------------------------------------------------------------------------- > > Key: HTTPCLIENT-881 > URL: https://issues.apache.org/jira/browse/HTTPCLIENT-881 > Project: HttpComponents HttpClient > Issue Type: Bug > Components: HttpConn > Affects Versions: 4.0 Final > Reporter: Tim Boemker > Fix For: 4.1 Alpha1 > > Attachments: HTTPCLIENT-881.patch > > > If HttpUriRequest.abort() is called at about the same time that the request completes, it's possible for an aborted connection to be returned to the pool. The next time the connection is used, HttpClient.execute fails without retrying, throwing this exception: > java.io.IOException: Connection already shutdown > at org.apache.http.impl.conn.DefaultClientConnection.opening(DefaultClientConnection.java:112) > at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:120) > at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:147) > at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:101) > at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:381) > at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641) > at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:576) > Steps to reproduce: > 1) Set a breakpoint in ThreadSafeClientConnManager.releaseConnection just after "reusable" is set (and found to be true). > 2) Run to the breakpoint in releaseConnection. > 3) Call HttpUriRequest.abort. > 4) Let releaseConnection complete. > When the connection is next used, the exception will be thrown. > Snippet from ThreadSafeClientConnManager: > public void releaseConnection(ManagedClientConnection conn, long validDuration, TimeUnit timeUnit) { > ... > boolean reusable = hca.isMarkedReusable(); > if (log.isDebugEnabled()) { // breakpoint here > if (reusable) { > log.debug("Released connection is reusable."); > } else { > log.debug("Released connection is not reusable."); > } > } > hca.detach(); > if (entry != null) { > connectionPool.freeEntry(entry, reusable, validDuration, timeUnit); > } > } > } > I think that AbstractClientConnAdapter should be modified as follows: > 1) Add "released" flag: > /** True if the connection has been released. */ > private boolean released; > 2) Modify abortConnection: > public void abortConnection() { > synchronized(this) { > if (aborted || released) { > return; > } > aborted = true; > } > unmarkReusable(); // this line and all that follow unchanged > 3) Modify releaseConnection: > public void releaseConnection() { > synchronized(this) { > if (aborted || released) { > return; > } > released = true; > } > if (connManager != null) { > connManager.releaseConnection(this, duration, TimeUnit.MILLISECONDS); > } > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org For additional commands, e-mail: dev-help@hc.apache.org