You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2015/10/13 18:37:29 UTC

svn commit: r1708465 - in /tomcat/trunk/java/org/apache/coyote/http2: Http2UpgradeHandler.java Stream.java

Author: markt
Date: Tue Oct 13 16:37:28 2015
New Revision: 1708465

URL: http://svn.apache.org/viewvc?rev=1708465&view=rev
Log:
Ensure that a Stream is only reset once. Second and subsequent resets
are NO-OPs.
Ensure that a Stream is not reset when it is closed. Resetting a closed
stream is a NO-OP.
Ensure that IDLE streams are not reset. Resetting an IDLE stream
triggers an ISE.

Modified:
    tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java
    tomcat/trunk/java/org/apache/coyote/http2/Stream.java

Modified: tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java?rev=1708465&r1=1708464&r2=1708465&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java Tue Oct 13 16:37:28 2015
@@ -410,25 +410,23 @@ public class Http2UpgradeHandler extends
         }
 
         Stream stream = getStream(se.getStreamId(), false);
-        if (stream != null) {
-            stream.sendRst();
-        }
-
-        // Write a RST frame
-        byte[] rstFrame = new byte[13];
-        // Length
-        ByteUtil.setThreeBytes(rstFrame, 0, 4);
-        // Type
-        rstFrame[3] = FrameType.RST.getIdByte();
-        // No flags
-        // Stream ID
-        ByteUtil.set31Bits(rstFrame, 5, se.getStreamId());
-        // Payload
-        ByteUtil.setFourBytes(rstFrame, 9, se.getError().getCode());
+        if (stream != null && stream.sendReset()) {
+            // Write a RST frame
+            byte[] rstFrame = new byte[13];
+            // Length
+            ByteUtil.setThreeBytes(rstFrame, 0, 4);
+            // Type
+            rstFrame[3] = FrameType.RST.getIdByte();
+            // No flags
+            // Stream ID
+            ByteUtil.set31Bits(rstFrame, 5, se.getStreamId());
+            // Payload
+            ByteUtil.setFourBytes(rstFrame, 9, se.getError().getCode());
 
-        synchronized (socketWrapper) {
-            socketWrapper.write(true, rstFrame, 0, rstFrame.length);
-            socketWrapper.flush(true);
+            synchronized (socketWrapper) {
+                socketWrapper.write(true, rstFrame, 0, rstFrame.length);
+                socketWrapper.flush(true);
+            }
         }
     }
 

Modified: tomcat/trunk/java/org/apache/coyote/http2/Stream.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/Stream.java?rev=1708465&r1=1708464&r2=1708465&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http2/Stream.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http2/Stream.java Tue Oct 13 16:37:28 2015
@@ -314,8 +314,21 @@ public class Stream extends AbstractStre
     }
 
 
-    void sendRst() {
-        state.sendReset();
+    /**
+     * Marks the stream as reset. This method will not change the stream state
+     * if:
+     * <ul>
+     * <li>The stream is already reset</li>
+     * <li>The stream is already closed</li>
+     *
+     * @return <code>true</code> if a reset frame needs to be sent to the peer,
+     *         otherwise <code>false</code>
+     *
+     * @throws IllegalStateException If the stream is in a state that does not
+     *         permit resets
+     */
+    boolean sendReset() {
+        return state.sendReset();
     }
 
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org