Author: markt
Date: Sat Aug 11 15:55:17 2018
New Revision: 1837871

URL: http://svn.apache.org/viewvc?rev=1837871&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=62614
HTTP/2 was not triggering calls to onWritePossible() after isReady() returned 
false and the window size was subsequently increased

Modified:
    tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java
    tomcat/trunk/java/org/apache/coyote/http2/LocalStrings.properties
    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=1837871&r1=1837870&r2=1837871&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java 
(original)
+++ tomcat/trunk/java/org/apache/coyote/http2/Http2UpgradeHandler.java Sat Aug 
11 15:55:17 2018
@@ -34,10 +34,12 @@ import java.util.concurrent.atomic.Atomi
 
 import javax.servlet.http.WebConnection;
 
+import org.apache.coyote.ActionCode;
 import org.apache.coyote.Adapter;
 import org.apache.coyote.CloseNowException;
 import org.apache.coyote.ProtocolException;
 import org.apache.coyote.Request;
+import org.apache.coyote.Response;
 import org.apache.coyote.http11.upgrade.InternalHttpUpgradeHandler;
 import org.apache.coyote.http2.HpackDecoder.HeaderEmitter;
 import org.apache.coyote.http2.HpackEncoder.State;
@@ -804,8 +806,23 @@ class Http2UpgradeHandler extends Abstra
 
         if (streamsToNotify != null) {
             for (AbstractStream stream : streamsToNotify) {
-                synchronized (stream) {
-                    stream.notifyAll();
+                if (log.isDebugEnabled()) {
+                    log.debug(sm.getString("upgradeHandler.releaseBacklog",
+                            connectionId, stream.getIdentifier()));
+                }
+                Response coyoteResponse = ((Stream) 
stream).getCoyoteResponse();
+                if (coyoteResponse.getWriteListener() == null) {
+                    // Blocking, so use notify to release StreamOutputBuffer
+                    synchronized (stream) {
+                        stream.notifyAll();
+                    }
+                } else {
+                    // Non-blocking so dispatch
+                    coyoteResponse.action(ActionCode.DISPATCH_WRITE, null);
+                    // Need to explicitly execute dispatches on the
+                    // StreamProcessor as this thread is being processed by an
+                    // UpgradeProcessor which won't see this dispatch
+                    coyoteResponse.action(ActionCode.DISPATCH_EXECUTE, null);
                 }
             }
         }

Modified: tomcat/trunk/java/org/apache/coyote/http2/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http2/LocalStrings.properties?rev=1837871&r1=1837870&r2=1837871&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http2/LocalStrings.properties [UTF-8] 
(original)
+++ tomcat/trunk/java/org/apache/coyote/http2/LocalStrings.properties [UTF-8] 
Sat Aug 11 15:55:17 2018
@@ -128,6 +128,7 @@ upgradeHandler.pruneIncomplete=Connectio
 upgradeHandler.pruneStart=Connection [{0}] Starting pruning of old streams. 
Limit is [{1}] + 10% and there are currently [{2}] streams.
 upgradeHandler.pruned=Connection [{0}] Pruned completed stream [{1}]
 upgradeHandler.prunedPriority=Connection [{0}] Pruned unused stream [{1}] that 
may have been part of the priority tree
+upgradeHandler.releaseBacklog=Connection [{0}], Stream [{1}] released from 
backlog
 upgradeHandler.rst.debug=Connection [{0}], Stream [{1}], Error [{2}], Message 
[{3}],  RST (closing stream)
 upgradeHandler.sendPrefaceFail=Connection [{0}], Failed to send preface to 
client
 upgradeHandler.socketCloseFailed=Error closing socket

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=1837871&r1=1837870&r2=1837871&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http2/Stream.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http2/Stream.java Sat Aug 11 15:55:17 
2018
@@ -196,7 +196,17 @@ class Stream extends AbstractStream impl
         boolean notify = getWindowSize() < 1;
         super.incrementWindowSize(windowSizeIncrement);
         if (notify && getWindowSize() > 0) {
-            notifyAll();
+            if (coyoteResponse.getWriteListener() == null) {
+                // Blocking, so use notify to release StreamOutputBuffer
+                notifyAll();
+            } else {
+                // Non-blocking so dispatch
+                coyoteResponse.action(ActionCode.DISPATCH_WRITE, null);
+                // Need to explicitly execute dispatches on the StreamProcessor
+                // as this thread is being processed by an UpgradeProcessor
+                // which won't see this dispatch
+                coyoteResponse.action(ActionCode.DISPATCH_EXECUTE, null);
+            }
         }
     }
 



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

Reply via email to