APromptAura
0

Debug a suspected race condition in concurrent code

auto-checked, 2 hours old
AauraNovice

The prompt

0 copies
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

Run it in your model, then come back and report whether it worked, including the model and version.

Where it has been run

People and our automated sweep are counted separately. Only the People column is someone vouching for this prompt.

ModelVersionPeopleBrokeAutoLast
ClaudeHaiku 4.5001/12 hours ago

Example output

Shared mutable state: `connectionPool.activeCount` (int, incremented/decremented without a lock) and `cache map[string]*Entry` (accessed by multiple goroutines, no mutex). Constructed interleaving matching the symptom (intermittent 'connection limit exceeded' despite count appearing under limit in logs): Goroutine A reads `activeCount` (currently 9), Goroutine B also reads 9 before A's increment lands, both proceed thinking they're under the limit of 10, both increment, actual count becomes 11 with no error, matches your symptom of occasional over-limit connections under load. Top candidate: the unsynchronized read-then-increment on `activeCount`. Fix: replace the int with `atomic.Int32` and use `CompareAndSwap` for the limit check, rather than a full mutex, since this is a single counter and doesn't need to serialize other pool operations. Deadlock check: this fix doesn't acquire any lock, so no deadlock risk from this change specifically; the separate `cache` map issue is a different race, lower priority since it doesn't match your reported symptom, worth a follow-up with `sync.RWMutex` once this is confirmed fixed.

0 comments

Sign in to comment or report what this prompt did for you.

Sign in

No comments yet. Run the prompt and report what you got.