This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push: new e0f23beb08 Handle spurious wake-ups while waiting for an allocation e0f23beb08 is described below commit e0f23beb08bdb6d56ea34adfaebba26af43bc3a1 Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Jul 6 14:05:48 2023 +0100 Handle spurious wake-ups while waiting for an allocation --- .../coyote/http2/WindowAllocationManager.java | 34 +++++++++++++++++----- webapps/docs/changelog.xml | 4 +++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/java/org/apache/coyote/http2/WindowAllocationManager.java b/java/org/apache/coyote/http2/WindowAllocationManager.java index 94558b15b1..e784c4083c 100644 --- a/java/org/apache/coyote/http2/WindowAllocationManager.java +++ b/java/org/apache/coyote/http2/WindowAllocationManager.java @@ -16,6 +16,8 @@ */ package org.apache.coyote.http2; +import java.util.concurrent.TimeUnit; + import org.apache.coyote.ActionCode; import org.apache.coyote.Response; import org.apache.juli.logging.Log; @@ -133,7 +135,7 @@ class WindowAllocationManager { } - private void waitFor(int waitTarget, long timeout) throws InterruptedException { + private void waitFor(int waitTarget, final long timeout) throws InterruptedException { synchronized (stream) { if (waitingFor != NONE) { throw new IllegalStateException(sm.getString("windowAllocationManager.waitFor.ise", @@ -141,12 +143,30 @@ class WindowAllocationManager { } waitingFor = waitTarget; - - if (timeout < 0) { - stream.wait(); - } else { - stream.wait(timeout); - } + long startNanos = -1; + + // Loop to handle spurious wake-ups + do { + if (timeout < 0) { + stream.wait(); + } else { + long timeoutRemaining; + if (startNanos == -1) { + startNanos = System.nanoTime(); + timeoutRemaining = timeout; + } else { + long elapsedMillis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos); + if (elapsedMillis == 0) { + elapsedMillis = 1; + } + timeoutRemaining = timeout - elapsedMillis; + if (timeoutRemaining <= 0) { + return; + } + } + stream.wait(timeoutRemaining); + } + } while (waitingFor != NONE); } } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index a25727b227..49da890896 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -159,6 +159,10 @@ code paths that could allow a notification from the Poller to be missed resuting in a timeout rather than the expected read or write. (markt) </fix> + <fix> + Refactor waiting for an HTTP/2 stream or connection window update to + handle spurious wake-ups during the wait. (markt) + </fix> </changelog> </subsection> <subsection name="WebSocket"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org