diff options
| author | Stefan Boberg <[email protected]> | 2026-03-31 14:38:32 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2026-03-31 14:38:32 +0200 |
| commit | 7fb3e142eba6c566079aa5d21078a8e66e1f0133 (patch) | |
| tree | 5ae2a15a3fd9b5c8784116c7408ff054fc9b2b12 | |
| parent | fix CI kill-process steps: use powershell on Windows, suppress pgrep exit cod... (diff) | |
| download | zen-sb/kill-test-procs.tar.xz zen-sb/kill-test-procs.zip | |
fix queue ActiveCount underflow race when session is abandoned during enqueuesb/kill-test-procs
NotifyQueueActionComplete unconditionally decremented ActiveCount, but
actions abandoned by the scheduler before ActivateActionInQueue ran were
never counted as active. Only decrement when the LSN was actually in
ActiveLsns, preventing the counter from going negative.
| -rw-r--r-- | src/zencompute/computeservice.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/zencompute/computeservice.cpp b/src/zencompute/computeservice.cpp index 58761556a..aaf34cbe2 100644 --- a/src/zencompute/computeservice.cpp +++ b/src/zencompute/computeservice.cpp @@ -1447,15 +1447,19 @@ ComputeServiceSession::Impl::NotifyQueueActionComplete(int QueueId, int Lsn, Run return; } + bool WasActive = false; Queue->m_Lock.WithExclusiveLock([&] { - Queue->ActiveLsns.erase(Lsn); + WasActive = Queue->ActiveLsns.erase(Lsn) > 0; Queue->FinishedLsns.insert(Lsn); }); - const int PreviousActive = Queue->ActiveCount.fetch_sub(1, std::memory_order_relaxed); - if (PreviousActive == 1) + if (WasActive) { - Queue->IdleSince.store(GetHifreqTimerValue(), std::memory_order_relaxed); + const int PreviousActive = Queue->ActiveCount.fetch_sub(1, std::memory_order_relaxed); + if (PreviousActive == 1) + { + Queue->IdleSince.store(GetHifreqTimerValue(), std::memory_order_relaxed); + } } switch (ActionState) |