意外连接在HTTPCLEINT中关闭



我在Web应用程序中面临HTTPCLIENT(版本4.5.2)的问题,我的意思是以多线程的方式。在正常情况下,当连接请求到达时,从池中租用了连接,然后使用并最终释放回池,以便将来再次使用作为与ID 673890州连接的日志的以下部分。

15 Feb 2017 018:25:54:115 p-1-thread-121 DEBUG PoolingHttpClientConnectionManager:249 - Connection request: [route: {}->http://127.0.0.1:8080][total kept alive: 51; route allocated: 4 of 100; total allocated: 92 of 500]
15 Feb 2017 018:25:54:116 p-1-thread-121 DEBUG PoolingHttpClientConnectionManager:282 - Connection leased: [id: 673890][route: {}->http://127.0.0.1:8080][total kept alive: 51; route allocated: 4 of 100; total allocated: 92 of 500]
15 Feb 2017 018:25:54:116 p-1-thread-121 DEBUG DefaultManagedHttpClientConnection:90 - http-outgoing-673890: set socket timeout to 9000
15 Feb 2017 018:25:54:120 p-1-thread-121 DEBUG PoolingHttpClientConnectionManager:314 - Connection [id: 673890][route: {}->http://127.0.0.1:8080] can be kept alive for 10.0 seconds
15 Feb 2017 018:25:54:121 p-1-thread-121 DEBUG PoolingHttpClientConnectionManager:320 - Connection released: [id: 673890][route: {}->http://127.0.0.1:8080][total kept alive: 55; route allocated: 4 of 100; total allocated: 92 of 500]

在使用上述连接(ID 673890)以正常方式使用后,我注意到代码中的以下情况:

15 Feb 2017 018:25:54:130 p-1-thread-126 DEBUG PoolingHttpClientConnectionManager:249 - Connection request: [route: {}->http://127.0.0.1:8080][total kept alive: 55; route allocated: 4 of 100; total allocated: 92 of 500]
15 Feb 2017 018:25:54:130 p-1-thread-126 DEBUG PoolingHttpClientConnectionManager:282 - Connection leased: [id: 673890][route: {}->http://127.0.0.1:8080][total kept alive: 54; route allocated: 4 of 100; total allocated: 92 of 500]
15 Feb 2017 018:25:54:131 p-1-thread-126 DEBUG DefaultManagedHttpClientConnection:90 - http-outgoing-673890: set socket timeout to 9000
15 Feb 2017 018:25:54:133 p-1-thread-126 DEBUG DefaultManagedHttpClientConnection:81 - http-outgoing-673890: Close connection
15 Feb 2017 018:25:54:133 p-1-thread-126 DEBUG PoolingHttpClientConnectionManager:320 - Connection released: [id: 673890][route: {}->http://127.0.0.1:8080][total kept alive: 55; route allocated: 3 of 100; total allocated: 91 of 500]

日志说该连接是请求,租赁,使用,关闭然后释放回池的。那么,我的问题是为什么连接关闭?为什么关闭后将其释放到游泳池?

我知道该连接可以由服务器关闭,但这是不同的情况。在这种情况下,连接是从池租用的,确定为陈旧,因此建立了新的连接和使用,但上面介绍的日志显示出不同的行为。

我知道HTTPClient中连接关闭的两个原因。首先,因为他们的Keepalivetime已过期,因此因闲置而关闭。其次,由服务器关闭,这使得池中的连接过时。是否有其他原因关闭连接?

基于Oleg Kalnichevski在httpclient邮件列表中的答复以及我所做的考试,事实证明问题是因为另一方面发送了"连接:关闭"标头。可能导致相同情况的另一个原因是使用http/1.0非势力连接。

最新更新