[
https://issues.apache.org/jira/browse/HTTPCLIENT-1151?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13166875#comment-13166875
]
Oleg Kalnichevski commented on HTTPCLIENT-1151:
-----------------------------------------------
I am fairly confident the content length is irrelevant and should have no
impact on connection management.
I tried to reproduce the problem using a local Tomcat 6.0.x instance and the
following code snippet and as far as I can tell HttpClient worked as
advertised.
---
try {
for (int i = 0; i < 2; i++) {
HttpGet httpget = new HttpGet("http://localhost:8080/empty.txt");
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
EntityUtils.consume(entity);
}
} finally {
httpclient.getConnectionManager().shutdown();
}
---
---
[DEBUG] SingleClientConnManager - Get connection for route
HttpRoute[{}->http://localhost:8080]
[DEBUG] DefaultClientConnectionOperator - Connecting to localhost:8080
[DEBUG] RequestAddCookies - CookieSpec selected: best-match
[DEBUG] RequestAuthCache - Auth cache not set in the context
[DEBUG] DefaultHttpClient - Attempt 1 to execute request
[DEBUG] DefaultClientConnection - Sending request: GET /empty.txt HTTP/1.1
[DEBUG] headers - >> GET /empty.txt HTTP/1.1
[DEBUG] headers - >> Host: localhost:8080
[DEBUG] headers - >> Connection: Keep-Alive
[DEBUG] headers - >> User-Agent: Apache-HttpClient/4.1.2 (java 1.5)
[DEBUG] DefaultClientConnection - Receiving response: HTTP/1.1 200 OK
[DEBUG] headers - << HTTP/1.1 200 OK
[DEBUG] headers - << Server: Apache-Coyote/1.1
[DEBUG] headers - << Accept-Ranges: bytes
[DEBUG] headers - << ETag: W/"0-1323525939000"
[DEBUG] headers - << Last-Modified: Sat, 10 Dec 2011 14:05:39 GMT
[DEBUG] headers - << Content-Type: text/plain
[DEBUG] headers - << Content-Length: 0
[DEBUG] headers - << Date: Sat, 10 Dec 2011 14:21:00 GMT
[DEBUG] DefaultHttpClient - Connection can be kept alive indefinitely
[DEBUG] SingleClientConnManager - Releasing connection
org.apache.http.impl.conn.SingleClientConnManager$ConnAdapter@2b275d39
[DEBUG] SingleClientConnManager - Get connection for route
HttpRoute[{}->http://localhost:8080]
[DEBUG] DefaultHttpClient - Stale connection check
[DEBUG] RequestAddCookies - CookieSpec selected: best-match
[DEBUG] RequestAuthCache - Auth cache not set in the context
[DEBUG] DefaultHttpClient - Attempt 1 to execute request
[DEBUG] DefaultClientConnection - Sending request: GET /empty.txt HTTP/1.1
[DEBUG] headers - >> GET /empty.txt HTTP/1.1
[DEBUG] headers - >> Host: localhost:8080
[DEBUG] headers - >> Connection: Keep-Alive
[DEBUG] headers - >> User-Agent: Apache-HttpClient/4.1.2 (java 1.5)
[DEBUG] DefaultClientConnection - Receiving response: HTTP/1.1 200 OK
[DEBUG] headers - << HTTP/1.1 200 OK
[DEBUG] headers - << Server: Apache-Coyote/1.1
[DEBUG] headers - << Accept-Ranges: bytes
[DEBUG] headers - << ETag: W/"0-1323525939000"
[DEBUG] headers - << Last-Modified: Sat, 10 Dec 2011 14:05:39 GMT
[DEBUG] headers - << Content-Type: text/plain
[DEBUG] headers - << Content-Length: 0
[DEBUG] headers - << Date: Sat, 10 Dec 2011 14:21:00 GMT
[DEBUG] DefaultHttpClient - Connection can be kept alive indefinitely
[DEBUG] SingleClientConnManager - Releasing connection
org.apache.http.impl.conn.SingleClientConnManager$ConnAdapter@2b5ac3c9
[DEBUG] DefaultClientConnection - Connection shut down
---
Feel free to run your application under debugger and find out whether or not
the response stream gets closed and the connection release is attempted.
Oleg
> DefaultHttpClient does not release connection if zero-length reply received
> ---------------------------------------------------------------------------
>
> Key: HTTPCLIENT-1151
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1151
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpClient
> Affects Versions: 4.1.1, 4.1.2
> Reporter: Sergey Alaev
> Attachments: wire.log
>
>
> When doing zero-length POST query using
> DefaultHttpClient/SingleClientConnManager it does not call
> SingleClientConnManager.releaseConnection
> Request: org.apache.http.HttpPost
> HTTP server response:
> HTTP/1.1 200 OK [Server: Apache-Coyote/1.1, Content-Length: 0, Date: Sat, 10
> Dec 2011 09:17:53 GMT, Connection: close]
> Exception when doing another request reusing that DefaultHttpClient:
> Caused by: java.lang.IllegalStateException: Invalid use of
> SingleClientConnManager: connection still allocated.
> Make sure to release the connection before allocating another one.
> at
> org.apache.http.impl.conn.SingleClientConnManager.getConnection(SingleClientConnManager.java:216)
> at
> org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:401)
> at
> org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
> We are using digest auth if that matters:
> request.addHeader("X-Requested-Auth", "Digest");
> httpclient.getCredentialsProvider().setCredentials(
> new AuthScope(targetHost.getHostName(), targetHost.getPort(),
> AuthScope.ANY_REALM),
> new UsernamePasswordCredentials(username, password));
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
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]