From 83307870b008506df98aa04d545ff4f7873b9f44 Mon Sep 17 00:00:00 2001 From: Dylan Myers Date: Mon, 3 Aug 2026 08:08:38 -0400 Subject: [PATCH] fix(count): guard Tracker.Acquire terminal close with mu to fix Acquire/Reset data race (PIPE-1231) Assisted-by: Claude Opus 4.8 --- generator/count/tracker.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/generator/count/tracker.go b/generator/count/tracker.go index bde1a6d..4bc9698 100644 --- a/generator/count/tracker.go +++ b/generator/count/tracker.go @@ -46,7 +46,13 @@ func (t *Tracker) Acquire() bool { } if t.remaining.CompareAndSwap(cur, cur-1) { if cur-1 == 0 { + // Guard doneOnce/doneCh with mu so this terminal-permit close + // is ordered against Reset(), which reassigns them under mu. + // The lock is taken only on the last permit, so the common + // acquire path stays lock-free (atomic CAS only). + t.mu.Lock() t.doneOnce.Do(func() { close(t.doneCh) }) + t.mu.Unlock() } return true }