src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java
branchhttp-client-branch
changeset 56616 5d2446adafaf
parent 56598 4c502e3991bf
child 56619 57f17e890a40
--- a/src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java	Thu May 24 18:41:30 2018 +0100
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java	Mon May 28 10:48:38 2018 +0100
@@ -837,23 +837,28 @@
                           streamid);
             }
         } finally {
+            decrementStreamsCount(streamid);
             closeStream(streamid);
         }
     }
 
+    // reduce count of streams by 1 if stream still exists
+    synchronized void decrementStreamsCount(int streamid) {
+        Stream<?> s = streams.get(streamid);
+        if (s == null || !s.deRegister())
+            return;
+        if (streamid % 2 == 1) {
+            numReservedClientStreams--;
+        } else {
+            numReservedServerStreams--;
+        }
+    }
+
     void closeStream(int streamid) {
         if (debug.on()) debug.log("Closed stream %d", streamid);
         boolean isClient = (streamid % 2) == 1;
         Stream<?> s = streams.remove(streamid);
         if (s != null) {
-            synchronized (this) {
-                if (isClient)
-                    numReservedClientStreams--;
-                else
-                    numReservedServerStreams--;
-            }
-            assert numReservedClientStreams >= 0;
-            assert numReservedServerStreams >= 0;
             // decrement the reference count on the HttpClientImpl
             // to allow the SelectorManager thread to exit if no
             // other operation is pending and the facade is no