http-client-branch: 8192962: issue with BUFFER_UNDERFLOW http-client-branch
authordfuchs
Mon, 04 Dec 2017 13:00:05 +0000
branchhttp-client-branch
changeset 55946 cfa4f84b7fcc
parent 55945 94fd10959e8b
child 55947 c4f314605d28
http-client-branch: 8192962: issue with BUFFER_UNDERFLOW
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Exchange.java
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/SSLFlowDelegate.java
src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/SubscriberWrapper.java
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Exchange.java	Sun Dec 03 20:56:29 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/Exchange.java	Mon Dec 04 13:00:05 2017 +0000
@@ -363,7 +363,7 @@
             // check for 101 switching protocols
             // 101 responses are not supposed to contain a body.
             //    => should we fail if there is one?
-            debug.log(Level.DEBUG, "Upgrading async %s" + e.connection());
+            debug.log(Level.DEBUG, "Upgrading async %s", e.connection());
             return e.readBodyAsync(this::ignoreBody, false, parentExecutor)
                 .thenCompose((T v) -> {// v is null
                     debug.log(Level.DEBUG, "Ignored body");
@@ -408,7 +408,7 @@
                                  s.cancelImpl(t);
                                  return MinimalFuture.failedFuture(t);
                             }
-                            debug.log(Level.DEBUG, "Getting response async %s" + s);
+                            debug.log(Level.DEBUG, "Getting response async %s", s);
                             return s.getResponseAsync(null);
                         });}
                 );
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/SSLFlowDelegate.java	Sun Dec 03 20:56:29 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/SSLFlowDelegate.java	Mon Dec 04 13:00:05 2017 +0000
@@ -318,6 +318,7 @@
                         if (result.status() == Status.BUFFER_UNDERFLOW) {
                             debugr.log(Level.DEBUG, "BUFFER_UNDERFLOW");
                             // not enough data in the read buffer...
+                            requestMore();
                             synchronized (readBufferLock) {
                                 // check if we have received some data
                                 if (readBuf.remaining() > len) continue;
--- a/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/SubscriberWrapper.java	Sun Dec 03 20:56:29 2017 +0000
+++ b/src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/SubscriberWrapper.java	Mon Dec 04 13:00:05 2017 +0000
@@ -76,6 +76,7 @@
     private final CompletableFuture<Void> cf;
     private final SequentialScheduler pushScheduler;
     private final AtomicReference<Throwable> errorRef = new AtomicReference<>();
+    final AtomicLong upstreamWindow = new AtomicLong(0);
 
     /**
      * Wraps the given downstream subscriber. For each call to {@link
@@ -309,8 +310,6 @@
         }
     }
 
-    AtomicLong upstreamWindow = new AtomicLong(0);
-
     void upstreamWindowUpdate() {
         long downstreamQueueSize = outputQ.size();
         long n = upstreamWindowUpdate(upstreamWindow.get(), downstreamQueueSize);
@@ -348,6 +347,12 @@
         upstreamSubscription.request(n);
     }
 
+    protected void requestMore() {
+        if (upstreamWindow.get() == 0) {
+            upstreamRequest(1);
+        }
+    }
+
     public long upstreamWindow() {
         return upstreamWindow.get();
     }