0
Debug a suspected race condition in concurrent code
I suspect a race condition in this concurrent/multithreaded code. Symptoms: symptoms. Help me find it systematically:
1. Identify every piece of shared mutable state the concurrent units touch, and for each, whether access is currently synchronized (and how) or not.
2. For unsynchronized shared state, construct the specific interleaving of operations across threads/goroutines/tasks that would produce the symptom I described, step by step (Thread A does X, then Thread B does Y before A finishes, causing Z).
3. Rank candidate races by how well the interleaving you constructed matches the actual symptom, don't just list every unsynchronized variable as equally suspicious.
4. Propose the minimal synchronization fix (a lock, an atomic, a channel, immutability) for the top candidate, and explain why it's sufficient without over-synchronizing (adding a lock that serializes more than necessary).
5. Note if the fix could introduce a deadlock given other locks already held in this codebase, and how to check for that.
Code: code
Concurrency model: {{concurrency_model, e.g. Go goroutines / Java threads / Python asyncio}}
Symptom details: symptoms