This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new ae16b5db8e Fix handling spurious wake-up reported by Coverity
ae16b5db8e is described below
commit ae16b5db8e8ec7776dd21873ca6a47b3f6b3a1e5
Author: Mark Thomas <[email protected]>
AuthorDate: Sat Aug 30 11:21:27 2025 +0100
Fix handling spurious wake-up reported by Coverity
---
.../group/interceptors/NonBlockingCoordinator.java | 26 +++++++++++++++-------
res/spotbugs/filter-false-positives.xml | 6 -----
webapps/docs/changelog.xml | 4 ++++
3 files changed, 22 insertions(+), 14 deletions(-)
diff --git
a/java/org/apache/catalina/tribes/group/interceptors/NonBlockingCoordinator.java
b/java/org/apache/catalina/tribes/group/interceptors/NonBlockingCoordinator.java
index 8c09e275d5..0efb5542b1 100644
---
a/java/org/apache/catalina/tribes/group/interceptors/NonBlockingCoordinator.java
+++
b/java/org/apache/catalina/tribes/group/interceptors/NonBlockingCoordinator.java
@@ -238,14 +238,24 @@ public class NonBlockingCoordinator extends
ChannelInterceptorBase {
new
CoordinationEvent(CoordinationEvent.EVT_PROCESS_ELECT, this, "Election, sending
request"));
sendElectionMsg(local, others[0], msg);
} else {
- try {
- coordMsgReceived.set(false);
- fireInterceptorEvent(new
CoordinationEvent(CoordinationEvent.EVT_WAIT_FOR_MSG, this,
- "Election, waiting for request"));
- electionMutex.wait(waitForCoordMsgTimeout);
- } catch (InterruptedException x) {
- Thread.currentThread().interrupt();
- }
+ coordMsgReceived.set(false);
+ fireInterceptorEvent(new
CoordinationEvent(CoordinationEvent.EVT_WAIT_FOR_MSG, this,
+ "Election, waiting for request"));
+ long timeout = waitForCoordMsgTimeout;
+ long timeoutEndNanos = System.nanoTime() + timeout * 1_000_000;
+ do {
+ try {
+ electionMutex.wait(timeout);
+ } catch (InterruptedException x) {
+ Thread.currentThread().interrupt();
+ }
+ timeout = (timeoutEndNanos - System.nanoTime()) /
1_000_000;
+ /*
+ * Spurious wake-ups are possible. Keep waiting if a) the
condition we were waiting for hasn't
+ * happened (i.e. notify() was not called) AND b) the
timeout has not expired AND c) the thread was
+ * not interrupted.
+ */
+ } while (suggestedviewId == null && !coordMsgReceived.get() &&
timeout > 0 && !Thread.interrupted());
String msg;
if (suggestedviewId == null && !coordMsgReceived.get()) {
if (Thread.interrupted()) {
diff --git a/res/spotbugs/filter-false-positives.xml
b/res/spotbugs/filter-false-positives.xml
index 51335dc915..3b1035550f 100644
--- a/res/spotbugs/filter-false-positives.xml
+++ b/res/spotbugs/filter-false-positives.xml
@@ -635,12 +635,6 @@
<Method name="move" />
<Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE" />
</Match>
- <Match>
- <!-- Monitor only used for election -->
- <Class
name="org.apache.catalina.tribes.group.interceptors.NonBlockingCoordinator"/>
- <Method name="startElection"/>
- <Bug pattern="WA_NOT_IN_LOOP"/>
- </Match>
<Match>
<Class
name="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Method name="memberAlive"/>
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 5145840eb6..29479a81e8 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -259,6 +259,10 @@
<subsection name="Cluster">
<changelog>
<!-- Entries for backport and removal before 12.0.0-M1 below this line
-->
+ <fix>
+ Handle spurious wake-ups during leader election for
+ <code>NonBlockingCoordinator</code>. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="WebSocket">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]