diff -r 818a23db260c -r 4254bed3c09d src/java.net.http/share/classes/jdk/internal/net/http/Http2ClientImpl.java --- a/src/java.net.http/share/classes/jdk/internal/net/http/Http2ClientImpl.java Wed Jun 20 17:15:16 2018 +0200 +++ b/src/java.net.http/share/classes/jdk/internal/net/http/Http2ClientImpl.java Wed Jun 20 09:05:57 2018 -0700 @@ -25,6 +25,9 @@ package jdk.internal.net.http; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.net.ConnectException; import java.net.InetSocketAddress; import java.net.URI; import java.util.Base64; @@ -95,15 +98,20 @@ synchronized (this) { Http2Connection connection = connections.get(key); if (connection != null) { - if (connection.closed || !connection.reserveStream(true)) { - if (debug.on()) - debug.log("removing found closed or closing connection: %s", connection); - deleteConnection(connection); - } else { - // fast path if connection already exists - if (debug.on()) - debug.log("found connection in the pool: %s", connection); - return MinimalFuture.completedFuture(connection); + try { + if (connection.closed || !connection.reserveStream(true)) { + if (debug.on()) + debug.log("removing found closed or closing connection: %s", connection); + deleteConnection(connection); + } else { + // fast path if connection already exists + if (debug.on()) + debug.log("found connection in the pool: %s", connection); + return MinimalFuture.completedFuture(connection); + } + } catch (IOException e) { + // thrown by connection.reserveStream() + return MinimalFuture.failedFuture(e); } } @@ -119,6 +127,11 @@ .whenComplete((conn, t) -> { synchronized (Http2ClientImpl.this) { if (conn != null) { + try { + conn.reserveStream(true); + } catch (IOException e) { + throw new UncheckedIOException(e); // shouldn't happen + } offerConnection(conn); } else { Throwable cause = Utils.getCompletionCause(t);