Alf Høgemark created HTTPCLIENT-1237:
----------------------------------------

             Summary: PoolingClientConnectionManager should only update pool 
expiry for resuable connections
                 Key: HTTPCLIENT-1237
                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1237
             Project: HttpComponents HttpClient
          Issue Type: Improvement
            Reporter: Alf Høgemark
            Priority: Minor
         Attachments: 1237.txt

When a HTTP 1.1 web server respons with a "Connection: close", the connection 
cannot be reused, and therefore it is not needed to update the "expiry time" 
for the connection in the pool.

Avoiding updating the expiry will also mean that we do not get somewhat 
confusing log messages like this for such a connection :
"
2012/09/25 19:16:55:845 CEST [DEBUG] PoolingClientConnectionManager - 
Connection [id: 2][route: {}->http://alf-quad:37442] can be kept alive for 
9223372036854775807 MILLISECONDS
"
I was testing against a web server which does not allow keep alive, so then I 
thought the pool was incorrectly reusing the connection when I saw this log 
line while debugging a connection related problem.

So I think the following change is correct :
Index: 
src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java
===================================================================
--- src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java 
(revision 1389988)
+++ src/main/java/org/apache/http/impl/conn/PoolingClientConnectionManager.java 
(working copy)
@@ -261,15 +261,18 @@
                         }
                     }
                 }
-                entry.updateExpiry(keepalive, tunit != null ? tunit : 
TimeUnit.MILLISECONDS);
-                if (this.log.isDebugEnabled()) {
-                    String s;
-                    if (keepalive > 0) {
-                        s = "for " + keepalive + " " + tunit;
-                    } else {
-                        s = "indefinitely";
+                // Only reusable connections can be kept alive
+                if(managedConn.isMarkedReusable()) {
+                    entry.updateExpiry(keepalive, tunit != null ? tunit : 
TimeUnit.MILLISECONDS);
+                    if (this.log.isDebugEnabled()) {
+                        String s;
+                        if (keepalive > 0) {
+                            s = "for " + keepalive + " " + tunit;
+                        } else {
+                            s = "indefinitely";
+                        }
+                        this.log.debug("Connection " + format(entry) + " can 
be kept alive " + s);
                     }
-                    this.log.debug("Connection " + format(entry) + " can be 
kept alive " + s);
                 }
             } finally {
                 this.pool.release(entry, managedConn.isMarkedReusable());


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to