Debug a Race Condition
Workflow for identifying and fixing timing-dependent bugs
CLAUDE.md
When debugging a suspected race condition:
- Confirm it’s timing-dependent: does the bug appear intermittently? Does it change behavior under load or with artificial delays?
- Identify the shared resource: what data or state are multiple operations reading/writing concurrently?
- Map the concurrent access patterns: which operations run in parallel, and where do they overlap?
- Add logging with timestamps and identifiers to each concurrent operation to trace the actual execution order.
- Fix with synchronization: use locks, transactions, atomic operations, or queues to serialize access to the shared resource.
- Test under load: run the scenario with concurrent requests to verify the fix eliminates the race.
Copy this workflow into your CLAUDE.md or agent config file so your agent follows this process automatically.