http-client-branch: Http2Connection should not try to send RST_STREAM if the channel is already closed http-client-branch
authordfuchs
Thu, 03 May 2018 18:27:32 +0100
branchhttp-client-branch
changeset 56513 17cb1166de81
parent 56507 2294c51eae30
child 56514 6ef5ca8283a4
http-client-branch: Http2Connection should not try to send RST_STREAM if the channel is already closed
src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java
--- a/src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java	Wed May 02 15:47:57 2018 +0100
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java	Thu May 03 18:27:32 2018 +0100
@@ -797,12 +797,22 @@
     }
 
     void resetStream(int streamid, int code) throws IOException {
-        Log.logError(
-            "Resetting stream {0,number,integer} with error code {1,number,integer}",
-            streamid, code);
-        ResetFrame frame = new ResetFrame(streamid, code);
-        sendFrame(frame);
-        closeStream(streamid);
+        try {
+            if (connection.channel().isOpen()) {
+                // no need to try & send a reset frame if the
+                // connection channel is already closed.
+                Log.logError(
+                        "Resetting stream {0,number,integer} with error code {1,number,integer}",
+                        streamid, code);
+                ResetFrame frame = new ResetFrame(streamid, code);
+                sendFrame(frame);
+            } else if (debug.on()) {
+                debug.log("Channel already closed, no need to reset stream %d",
+                          streamid);
+            }
+        } finally {
+            closeStream(streamid);
+        }
     }
 
     void closeStream(int streamid) {