From 8f7c76ee1a05851f76a047671e3648c11b40feac Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Mon, 17 Aug 2026 16:50:19 -0400 Subject: [PATCH] Preserve the deadline in IceGrid ServerEntry synchronization waits ServerEntry shares the Allocatable mutex and condition variable, so the condition variable is also notified by allocation state transitions. waitImpl restarted a full wait_for(timeout) on every wake-up, so such notifications during a pending synchronization could extend the wait well past the requested timeout. Wait on an absolute deadline with a predicate instead. Addresses part of item 2 of #6626. Co-Authored-By: Claude Fable 5 --- cpp/src/IceGrid/ServerCache.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/cpp/src/IceGrid/ServerCache.cpp b/cpp/src/IceGrid/ServerCache.cpp index 0e94f83f82b..e492ca92d6d 100644 --- a/cpp/src/IceGrid/ServerCache.cpp +++ b/cpp/src/IceGrid/ServerCache.cpp @@ -707,22 +707,13 @@ void ServerEntry::waitImpl(chrono::seconds timeout) { unique_lock lock(_mutex); - if (timeout != 0s) + if (timeout > 0s) { - while (_synchronizing) - { - if (timeout > 0s) - { - if (_condVar.wait_for(lock, timeout) == cv_status::timeout) - { - break; // Timeout - } - } - else - { - _condVar.wait(lock); - } - } + _condVar.wait_until(lock, chrono::steady_clock::now() + timeout, [this] { return !_synchronizing; }); + } + else if (timeout < 0s) + { + _condVar.wait(lock, [this] { return !_synchronizing; }); } if (_synchronizing) // If we are still synchronizing, throw SynchronizationException {