From fd8806e441aa4a540dca9e4a85dca3d794e08c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Paksy?= Date: Wed, 27 May 2026 16:40:08 +0200 Subject: [PATCH] ZOOKEEPER-5052: Fix stale thread write of primitive in JvmPauseMonitor Change the three counter fields to volatile to ensure cross-thread visibility when the getters are called from threads other than the monitor thread. This prevents the JVM caching the stale 0 value. Under CI load or with aggressive JIT optimizations, this manifests as an intermittent 5-second timeout. --- .../org/apache/zookeeper/server/util/JvmPauseMonitor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/util/JvmPauseMonitor.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/util/JvmPauseMonitor.java index cdefb5d297c..4a06f3db92d 100644 --- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/util/JvmPauseMonitor.java +++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/util/JvmPauseMonitor.java @@ -64,9 +64,9 @@ public class JvmPauseMonitor { public static final String INFO_THRESHOLD_KEY = "jvm.pause.info-threshold.ms"; public static final long INFO_THRESHOLD_DEFAULT = 1000; - private long numGcWarnThresholdExceeded = 0; - private long numGcInfoThresholdExceeded = 0; - private long totalGcExtraSleepTime = 0; + private volatile long numGcWarnThresholdExceeded = 0; + private volatile long numGcInfoThresholdExceeded = 0; + private volatile long totalGcExtraSleepTime = 0; private Thread monitorThread; private volatile boolean shouldRun = true;