src/java.net.http/share/classes/jdk/internal/net/http/common/SubscriberWrapper.java
branchhttp-client-branch
changeset 56207 03c89ed2070f
parent 56092 fd85b2bf2b0d
child 56208 d37c08ce784a
--- a/src/java.net.http/share/classes/jdk/internal/net/http/common/SubscriberWrapper.java	Tue Feb 27 16:44:39 2018 +0000
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/common/SubscriberWrapper.java	Tue Feb 27 18:43:06 2018 +0000
@@ -92,7 +92,11 @@
     public SubscriberWrapper()
     {
         this.outputQ = new ConcurrentLinkedQueue<>();
-        this.cf = new MinimalFuture<>();
+        this.cf = new MinimalFuture<Void>().whenComplete((v,t) ->
+        {
+            if (t != null)
+                errorCommon(t, false);
+        });
         this.pushScheduler =
                 SequentialScheduler.synchronizedScheduler(new DownstreamPusher());
         this.downstreamSubscription = new SubscriptionBase(pushScheduler,
@@ -255,7 +259,7 @@
             try {
                 run1();
             } catch (Throwable t) {
-                errorCommon(t);
+                errorCommon(t, true);
             }
         }
 
@@ -363,17 +367,18 @@
     @Override
     public void onError(Throwable throwable) {
         logger.log(Level.DEBUG, () -> "onError: " + throwable);
-        errorCommon(Objects.requireNonNull(throwable));
+        errorCommon(Objects.requireNonNull(throwable), true);
     }
 
-    protected boolean errorCommon(Throwable throwable) {
+    protected boolean errorCommon(Throwable throwable, boolean completecf) {
         assert throwable != null ||
                 (throwable = new AssertionError("null throwable")) != null;
         if (errorRef.compareAndSet(null, throwable)) {
             logger.log(Level.DEBUG, "error", throwable);
             pushScheduler.runOrSchedule();
             upstreamCompleted = true;
-            cf.completeExceptionally(throwable);
+            if (completecf)
+                cf.completeExceptionally(throwable);
             return true;
         }
         return false;
@@ -381,14 +386,18 @@
 
     @Override
     public void close() {
-        errorCommon(new RuntimeException("wrapper closed"));
+        errorCommon(new RuntimeException("wrapper closed"), true);
+    }
+
+    public void close(Throwable t) {
+        errorCommon(t, true);
     }
 
     private void incomingCaller(List<ByteBuffer> l, boolean complete) {
         try {
             incoming(l, complete);
         } catch(Throwable t) {
-            errorCommon(t);
+            errorCommon(t, true);
         }
     }