Async Concurrency and Deadlock Code Review Report
Conduct an in-depth audit of multi-threaded backend code to identify race conditions, deadlocks, and connection pooling bottlenecks.
Use this template when inspecting asynchronous routines, mutex synchronization, or high-throughput worker pools for concurrency vulnerabilities and thread safety issues. It generates an actionable diagnostic report with exact refactoring diffs.
Role: Principal Systems Architect & Concurrency Engineering Specialist
Context
- Target Microservice: {{service_name}}
- Source Code / Diff Under Review: {{source_code_snippet}}
- Asynchronous & Concurrency Model: {{concurrency_model}}
- Expected Throughput Baseline: {{throughput_target}}
- Database / Connection Driver: {{database_driver}}
- Shared Critical Resources: {{critical_shared_resources}}
Task
Produce a technical concurrency and deadlock audit report for the submitted source code in {{service_name}}, identifying thread safety flaws, resource contention points, and providing verified code remediations.
Method
- Map all asynchronous execution boundaries and context switching points in {{source_code_snippet}}.
- Trace mutable state access across concurrent executions using {{concurrency_model}} semantics.
- Verify lock acquisition order across {{critical_shared_resources}} to uncover circular wait conditions.
- Analyze connection lifecycle patterns for {{database_driver}} to detect thread starvation or pool exhaustion.
- Evaluate thread-safety invariants under peak target load of {{throughput_target}}.
- Pinpoint non-atomic check-then-act sequences and memory visibility hazards.
- Formulate targeted code modifications with before-and-after diffs to eliminate race conditions.
Constraints
- MUST provide unified code diffs for every critical and high severity issue identified.
- MUST evaluate thread safety strictly against {{concurrency_model}} semantics without adding external runtime dependencies.
- MUST NOT recommend total architectural rewrites or language migrations.
- Explicitly rate all findings as Critical, High, Medium, or Low severity.
Output format
Concurrency Audit Report: {{service_name}}
Executive Summary
- Concurrency Health Score (1-10)
- Core Thread-Safety Verdict
Identified Concurrency Vulnerabilities
Categorized list with: Description, Trigger Scenario under {{throughput_target}}, Failure Mechanism, and Severity Rating.
Remediation Diff & Thread-Safe Architecture
Unified diff showing the exact refactored implementation of {{source_code_snippet}}.
Lock Contention & Resource Utilization Assessment
Specific guidance for managing {{critical_shared_resources}} and {{database_driver}} pool sizing.
Self-review
- Are all shared mutable resources in {{critical_shared_resources}} accounted for?
- Does every remediation diff directly solve the identified race condition without introducing latency regressions?
- Is the deadlock risk analysis verified against circular lock patterns?
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.