This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new bfb9b3c87c Fix handling of spurious wake-ups while waiting for network
read/write
bfb9b3c87c is described below
commit bfb9b3c87cfd1e74dc701b6db617fcd95044e5b9
Author: Mark Thomas <[email protected]>
AuthorDate: Sat Aug 30 16:55:23 2025 +0100
Fix handling of spurious wake-ups while waiting for network read/write
---
java/org/apache/tomcat/util/net/SocketWrapperBase.java | 8 +++++++-
res/spotbugs/filter-false-positives.xml | 6 ------
webapps/docs/changelog.xml | 4 ++++
3 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/java/org/apache/tomcat/util/net/SocketWrapperBase.java
b/java/org/apache/tomcat/util/net/SocketWrapperBase.java
index 1457791521..214d984356 100644
--- a/java/org/apache/tomcat/util/net/SocketWrapperBase.java
+++ b/java/org/apache/tomcat/util/net/SocketWrapperBase.java
@@ -1359,7 +1359,13 @@ public abstract class SocketWrapperBase<E> {
synchronized (state) {
if (state.state == CompletionState.PENDING) {
try {
- state.wait(unit.toMillis(timeout));
+ long timeoutExpiry = System.nanoTime() +
unit.toNanos(timeout);
+ long timeoutMillis = unit.toMillis(timeout);
+ // Spurious wake-ups are possible. Keep waiting until
state changes or timeout expires.
+ while (state.state == CompletionState.PENDING &&
timeoutMillis > 0) {
+ state.wait(unit.toMillis(timeout));
+ timeoutMillis = (timeoutExpiry -
System.nanoTime()) / 1_000_000;
+ }
if (state.state == CompletionState.PENDING) {
if (handler != null &&
state.callHandler.compareAndSet(true, false)) {
handler.failed(new
SocketTimeoutException(getTimeoutMsg(read)), attachment);
diff --git a/res/spotbugs/filter-false-positives.xml
b/res/spotbugs/filter-false-positives.xml
index 274cc44f37..9d6ac30455 100644
--- a/res/spotbugs/filter-false-positives.xml
+++ b/res/spotbugs/filter-false-positives.xml
@@ -1670,12 +1670,6 @@
<Bug code="SF" />
</Match>
<Match>
- <!-- Single condition so fine -->
- <Class name="org.apache.tomcat.util.net.SocketWrapperBase" />
- <Method name="vectoredOperation"/>
- <Bug pattern="WA_NOT_IN_LOOP" />
- </Match>
- <Match>
<!-- Single condition so notify is fine -->
<Class
name="org.apache.tomcat.util.net.SocketWrapperBase$VectoredIOCompletionHandler"
/>
<Or>
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 8b9c122ebe..78fef52b86 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -141,6 +141,10 @@
Add new <code>ML-DSA</code> key algorithm to <code>PEMFile</code>
and improve reporting when reading a key fails. (remm)
</fix>
+ <fix>
+ Fix possible early timeouts for network operations caused by a spurious
+ wake-up of a waiting thread. Found by Coverity Scan. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Cluster">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]