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 ba7fbd9413 Fix handling spurious wake-up reported by Coverity ba7fbd9413 is described below commit ba7fbd9413968c5cc679970112b062c97a182ab2 Author: Mark Thomas <ma...@apache.org> 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 | 8 +++++++ 3 files changed, 26 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 727aaa4093..eb03b25810 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 d9c9a7e84e..8d4c50c8c3 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 89b4bbcd17..d5cb47166d 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -135,6 +135,14 @@ </fix> </changelog> </subsection> + <subsection name="Cluster"> + <changelog> + <fix> + Handle spurious wake-ups during leader election for + <code>NonBlockingCoordinator</code>. (markt) + </fix> + </changelog> + </subsection> <subsection name = "Other"> <changelog> <scode> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org