jira-importer opened a new issue, #1230: URL: https://github.com/apache/httpcomponents-core/issues/1230
**[Sylvain POGNANT](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=s.pognant)** opened **[HTTPCORE-683](https://issues.apache.org/jira/browse/HTTPCORE-683?redirect=false)** and commented There is an implementation problem in **AbstractIOSessionPool.getSessionInternal()** Wrong pattern (starting line 190 in httpcore5-5.1.1) : if (poolEntry.sessionFuture == null) { **poolEntry.sessionFuture =** connectSession( namedEndpoint, connectTimeout, new FutureCallback\<IOSession>() { ... `@Override` public void failed(final Exception ex) { synchronized (poolEntry) { poolEntry.session = null; **poolEntry.sessionFuture = null;** ... } } ... }); In case of a synchronous failure during connectSession (for example : UnknownHostException), the sessionFuture cleanup in the failed() callback (line 216) is executed +before+ poolEntry.sessionFuture is assigned with the return value of connectSession (line 191) Thus, after the failure, a cancelled future is assigned to poolEntry.sessionFuture and never cleaned up ! This result in a stalled entry in the pool because the _if (poolEntry.sessionFuture == null)_ condition will no longer return true. **Quick Reproducer** H2AsyncClientBuilder httpClientBuilder = HttpAsyncClients.customHttp2() .setDefaultRequestConfig(RequestConfig.custom() .setConnectTimeout(5000, TimeUnit.MILLISECONDS) .setResponseTimeout(5000, TimeUnit.MILLISECONDS) .build()) .setH2Config(H2Config.custom() .setPushEnabled(false) .build()); CloseableHttpAsyncClient client = httpClientBuilder.build(); client.start(); for(int n=1;n<=2;n++) { System.out.println("Try #"+n); HttpHost targetHost = new HttpHost(URIScheme.HTTPS.getId(), "invalidhost-gfhsgfxyzd.com", 443); SimpleHttpRequest request = new SimpleHttpRequest("GET", targetHost, "/"); Future\<SimpleHttpResponse> responseFuture = client.execute(request, null); try { responseFuture.get(); // **HANGS FOREVER at Try `#2`** } catch (ExecutionException e) { e.printStackTrace(); } } **Quick Fix** Cleaning the sessionFuture immediately after connectSession() returns in case its already done fixes the issue : (Line 234) + if (poolEntry.sessionFuture != null && poolEntry.sessionFuture.isDone()) + poolEntry.sessionFuture = null; --- **Affects:** 5.1.1 **Issue Links:** - [HTTPCORE-750](https://issues.apache.org/jira/browse/HTTPCORE-750) H2ConnPool creates too many conns under high load at initialization time (_**"is cloned by"**_) **Backported to:** [5.1.2](https://github.com/apache/httpcomponents-core/milestone/74?closed=1) -- 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]
