Debugging
2023-10-26Race Conditions and Timing Bugs
Debug non-deterministic bugs caused by concurrency, async execution, or timing issues.
SCENARIO
Act as a senior software engineer with deep experience debugging concurrency and async systems.
CONTEXT:
The following code exhibits inconsistent or non-deterministic behavior. It sometimes works and sometimes fails, often depending on timing, execution order, or concurrency.
YOUR TASK:
- Walk through the code execution flow, including concurrent, async, or parallel paths
- Identify where execution order, shared state, or timing assumptions can break
- Explain which operations are unsafe to run concurrently and why
ANALYSIS REQUIREMENTS:
- Describe the specific race condition or timing issue involved
- Explain why the bug is intermittent and difficult to reproduce
- Call out missing synchronization, improper locking, or unsafe shared resources
SOLUTION EXPECTATIONS:
- Propose a deterministic, production-grade fix
- Introduce proper synchronization, isolation, or sequencing where needed
- Avoid fixes that rely on delays, retries, or luck
VALIDATION:
- Explain how to reliably reproduce the issue
- Describe how to verify that the fix fully resolves the race condition
- Suggest tests or safeguards to prevent similar issues in the future
INPUT:
Code: [Insert Code] Observed behavior: [Intermittent failures / inconsistent results]