ApacheConnector's breaks any connecting pool by always forcing all connections to be close and not released back to the pool.
The PR/change introduced in #3124 causes connection pooling to break.
When response.close()(https://github.com/jersey/jersey/commit/0d1326dee69d9c693014184bea3e4a44b323daee#diff-91ece5335d0cdc9321a099df1caec54fR643) is called this causes Apache HttpClient to not release the connection back to the pool but close it instead.
The flow is: HttpClientResponseInputStream.close() -> CloseableHttpResponse.close() -> HttpResponseProxy.close() -> ConnectionHolder.close() -> ConnectionHolder.releaseConnection(false)…. releaseConnection(false) causes the underlying connection to be closed and not released back to the pool for reuse.
Affected Versions
[2.25.1]
Reported by aaronjwhiteside
@pavelbucek said: Are you sure that the linked issue #3123 is correct? I do see it as resolved/invalid, which implies that there is no associated commit.
@pavelbucek said: It should be #3124. Edited the original description.
aaronjwhiteside said:
I've narrowed down the issue to the type of the entity you request when calling .get()
ClientConfig config = new ClientConfig();
config.connectorProvider(new ApacheConnectorProvider());
Client client = ClientBuilder.newClient(config);
WebTarget target = client.target(getHttpBaseUrl());
// complex (jackson annotated)
target.path("/test").request().get(Model.class);
target.path("/test").request().get(Model.class);
// String
target.path("/test").request().get(String.class);
target.path("/test").request().get(String.class);
Debug Model.class, notice the Close connection log line:
20:24:34.197 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://127.0.0.1:56848][total kept alive: 0; route allocated: 0 of 10; total allocated: 0 of 10] 20:24:34.206 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {}->http://127.0.0.1:56848][total kept alive: 0; route allocated: 1 of 10; total allocated: 1 of 10] 20:24:34.509 [main] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-0: Close connection
20:24:34.510 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {}->http://127.0.0.1:56848][total kept alive: 0; route allocated: 0 of 10; total allocated: 0 of 10] 20:24:34.511 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://127.0.0.1:56848][total kept alive: 0; route allocated: 0 of 10; total allocated: 0 of 10] 20:24:34.511 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection leased: [id: 1][route: {}->http://127.0.0.1:56848][total kept alive: 0; route allocated: 1 of 10; total allocated: 1 of 10] 20:24:34.516 [main] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-1: Close connection
20:24:34.516 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 1][route: {}->http://127.0.0.1:56848][total kept alive: 0; route allocated: 0 of 10; total allocated: 0 of 10]
Debug with String.class
20:36:23.888 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://127.0.0.1:57019][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20] 20:36:23.896 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {}->http://127.0.0.1:57019][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20] 20:36:24.222 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {}->http://127.0.0.1:57019][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20] 20:36:24.225 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection request: [route: {}->http://127.0.0.1:57019][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20] 20:36:24.225 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection leased: [id: 1][route: {}->http://127.0.0.1:57019][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20] 20:36:24.229 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 1][route: {}->http://127.0.0.1:57019][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
Both of these were verified using wireshark.
Issue-Links: is related to JERSEY-2852
This issue was imported from java.net JIRA JERSEY-3260
Hi - I'm running into this problem as well, is there an update that solves this?