src/java.net.http/share/classes/jdk/internal/net/http/Http2ClientImpl.java
branchhttp-client-branch
changeset 56598 4c502e3991bf
parent 56507 2294c51eae30
child 56795 03ece2518428
--- a/src/java.net.http/share/classes/jdk/internal/net/http/Http2ClientImpl.java	Fri May 18 15:23:56 2018 +0100
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/Http2ClientImpl.java	Wed May 23 16:44:13 2018 +0100
@@ -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);