src/java.net.http/share/classes/jdk/internal/net/http/Http1Exchange.java
changeset 49944 4690a2871b44
parent 49765 ee6f7a61f3a5
child 50681 4254bed3c09d
child 56507 2294c51eae30
--- a/src/java.net.http/share/classes/jdk/internal/net/http/Http1Exchange.java	Wed May 02 10:47:16 2018 +0200
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/Http1Exchange.java	Wed May 02 02:36:17 2018 -0700
@@ -259,8 +259,19 @@
         if (!connection.connected()) {
             if (debug.on()) debug.log("initiating connect async");
             connectCF = connection.connectAsync();
+            Throwable cancelled;
             synchronized (lock) {
-                operations.add(connectCF);
+                if ((cancelled = failed) == null) {
+                    operations.add(connectCF);
+                }
+            }
+            if (cancelled != null) {
+                if (client.isSelectorThread()) {
+                    executor.execute(() ->
+                        connectCF.completeExceptionally(cancelled));
+                } else {
+                    connectCF.completeExceptionally(cancelled);
+                }
             }
         } else {
             connectCF = new MinimalFuture<>();
@@ -403,6 +414,9 @@
             if ((error = failed) == null) {
                 failed = error = cause;
             }
+            if (debug.on()) {
+                debug.log(request.uri() + ": " + error);
+            }
             if (requestAction != null && requestAction.finished()
                     && response != null && response.finished()) {
                 return;
@@ -447,7 +461,7 @@
                 exec.execute(() -> {
                     if (cf.completeExceptionally(x)) {
                         if (debug.on())
-                            debug.log("completed cf with %s", (Object) x);
+                            debug.log("%s: completed cf with %s", request.uri(), x);
                     }
                 });
             }