jira-importer opened a new issue, #1067: URL: https://github.com/apache/httpcomponents-core/issues/1067
**[Desmond Yeung](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=desmondyeung)** opened **[HTTPCORE-560](https://issues.apache.org/jira/browse/HTTPCORE-560?redirect=false)** and commented I'm currently using HttpClient 5.0-beta1/HttpCore 5.0-beta2 and run into the following stacktrace fairly often in a production environment: ```java java.lang.IllegalStateException: Pool entry already present in the set of leased entries at org.apache.hc.core5.pool.LaxConnPool$PerRoutePool.addLeased(LaxConnPool.java:393) at org.apache.hc.core5.pool.LaxConnPool$PerRoutePool.lease(LaxConnPool.java:429) at org.apache.hc.core5.pool.LaxConnPool.lease(LaxConnPool.java:143) at org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManager.lease(PoolingAsyncClientConnectionManager.java:216) at org.apache.hc.client5.http.impl.async.InternalHttpAsyncExecRuntime.acquireConnection(InternalHttpAsyncExecRuntime.java:89) at org.apache.hc.client5.http.impl.async.AsyncConnectExec.execute(AsyncConnectExec.java:152) at org.apache.hc.client5.http.impl.async.AsyncExecChainElement.execute(AsyncExecChainElement.java:54) at org.apache.hc.client5.http.impl.async.AsyncExecChainElement$1.proceed(AsyncExecChainElement.java:62) at org.apache.hc.client5.http.impl.async.AsyncProtocolExec.internalExecute(AsyncProtocolExec.java:170) at org.apache.hc.client5.http.impl.async.AsyncProtocolExec.execute(AsyncProtocolExec.java:133) at org.apache.hc.client5.http.impl.async.AsyncExecChainElement.execute(AsyncExecChainElement.java:54) at org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient$1.sendRequest(InternalAbstractHttpAsyncClient.java:170) at org.apache.hc.core5.http.nio.BasicRequestProducer.sendRequest(BasicRequestProducer.java:65) at org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient.execute(InternalAbstractHttpAsyncClient.java:144) at org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient.execute(CloseableHttpAsyncClient.java:78) ``` After doing some digging I believe that `addLeased(releasedEntry);` should be replaced with `addLeased(availableEntry);` in the following snippet of `PerRoutePool#release`. In it's current state, it appears that the polled `leaseRequest` gets leaked when this happens. Please let me know if my findings are correct. ```java while ((leaseRequest = pending.poll()) != null) { if (leaseRequest.isDone()) { continue; } final Object state = leaseRequest.getState(); final Deadline deadline = leaseRequest.getDeadline(); if (deadline.isExpired()) { leaseRequest.failed(DeadlineTimeoutException.from(deadline)); } else { final PoolEntry<T, C> availableEntry = getAvailableEntry(state); if (availableEntry != null) { addLeased(releasedEntry); leaseRequest.completed(availableEntry); } else if (leased.size() < max) { final PoolEntry<T, C> newEntry = new PoolEntry<>(route, timeToLive); addLeased(newEntry); leaseRequest.completed(newEntry); } break; } } ``` --- **Affects:** 5.0-beta5 **Remote Links:** - [GitHub Pull Request `#92` ](https://github.com/apache/httpcomponents-core/pull/92) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
