[
https://issues.apache.org/jira/browse/HTTPCLIENT-1887?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16276256#comment-16276256
]
wenqi.huang commented on HTTPCLIENT-1887:
-----------------------------------------
No, but I think the `Socket.close() ` should not be the responsibility of evict
thread.
> tcp status remains in ·CLOSE_WAIT· for a very long time
> -------------------------------------------------------
>
> Key: HTTPCLIENT-1887
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1887
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpClient (classic)
> Affects Versions: 4.5.3
> Reporter: wenqi.huang
>
> run the following code, after the request completed, then wait for some
> seconds, you can use `netstat -an | grep {the server ip}` to see the tcp
> status, the tcp status will transform from `ESTABLISHED` to `CLOSE_WAIT`. and
> it remains in `CLOSE_WAIT` for a very long time, this only happen when the
> server want to close the tcp connection, but the client does not send `FIN`
> to the server.
> {code:java}
> package cn.com.duibaboot.ext.autoconfigure.httpclient;
> import org.apache.commons.io.IOUtils;
> import org.apache.http.HttpResponse;
> import org.apache.http.client.methods.CloseableHttpResponse;
> import org.apache.http.client.methods.HttpGet;
> import org.apache.http.client.methods.HttpUriRequest;
> import org.apache.http.impl.client.CloseableHttpClient;
> import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy;
> import org.apache.http.impl.client.HttpClientBuilder;
> import org.apache.http.protocol.HttpContext;
> import java.io.IOException;
> public class HttpClientTest1 {
> public static void main(String[] args) throws InterruptedException {
> final CloseableHttpClient httpClient = HttpClientBuilder
> .create()
> .setKeepAliveStrategy(new
> DefaultConnectionKeepAliveStrategy(){
> @Override
> public long getKeepAliveDuration(HttpResponse response,
> HttpContext context) {
> long time = super.getKeepAliveDuration(response,
> context);
> if(time == -1){
> time = 30000;
> }
> return time;
> }
> })
> .build();
> HttpUriRequest req = new HttpGet("http://www.duiba.com.cn");
> try {
> CloseableHttpResponse r = httpClient.execute(req);
> IOUtils.toByteArray(r.getEntity().getContent());
> r.getEntity().getContent().close();
> } catch (IOException e) {
> e.printStackTrace();
> }
> Thread.sleep(Integer.MAX_VALUE);
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]