Identify potential race conditions
✓Works with OpenClaudeYou are a concurrency debugging expert. The user wants to identify potential race conditions in their codebase by analyzing concurrent code patterns, shared state access, and synchronization gaps.
What to check first
- Run
go vet ./...(Go) or useclang --analyze(C/C++) to catch basic race detector warnings - Check if your project has race detection enabled:
go test -race ./...for Go, or compile with-fsanitize=threadfor C/C++ - Inspect your codebase for shared mutable state: grep for
var,global,static, orthis.propertyassignments within concurrent contexts
Steps
- Enable race detection in your build/test pipeline with language-specific tools (
-raceflag for Go, ThreadSanitizer for C/C++, or Helgrind for general binaries) - Identify all goroutines, threads, or async tasks that access shared variables—look for
go func(),Thread.start(), orPromise/asyncpatterns - Map which variables are accessed from multiple concurrent execution paths without synchronization primitives
- Check for missing locks: search for mutex usage patterns like
mu.Lock()and verify all access to the protected variable is guarded - Look for channel operations that might deadlock—ensure all sends/receives have corresponding partners and no goroutines block indefinitely
- Audit atomic operations: if using
atomic.Load/Store, verify you're not mixing atomic and non-atomic access to the same variable - Trace callback chains and event listeners for non-deterministic ordering that could expose stale reads
- Run integration tests under stress with
-raceenabled to surface timing-dependent issues that static analysis misses
Code
package main
import (
"fmt"
"sync"
"sync/atomic"
)
type AccountService struct {
balance int64
mu sync.RWMutex
logs []string
logLock sync.Mutex
}
func (as *AccountService) SafeDeposit(amount int64) error {
as.mu.Lock()
defer as.mu.Unlock()
as.balance += amount
as.logOperation("deposit", amount)
return nil
}
func (as *AccountService) SafeWithdraw(amount int64) error {
as.mu.Lock()
defer as.mu.Unlock()
if as.balance < amount {
return fmt.Errorf("insufficient funds")
}
as.balance -= amount
as.logOperation("withdraw", amount)
return nil
}
func (as *AccountService) SafeGetBalance() int64 {
as.mu.RLock()
defer as.mu.RUnlock()
return as.balance
}
func (as *AccountService) logOperation(op string, amount int64) {
as.logLock.Lock()
defer as.logLock.Unlock()
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Debugging Skills
Other Claude Code skills in the same category — free to download.
Error Analyzer
Analyze error messages and suggest fixes
Stack Trace Decoder
Decode and explain stack traces
Memory Leak Finder
Find and fix memory leaks
Performance Profiler
Profile code and identify bottlenecks
Log Analyzer
Analyze log files and identify patterns
Network Debugger
Debug network/HTTP request issues
Deadlock Detector
Find potential deadlocks in concurrent code
Environment Diff
Compare environment configurations
Want a Debugging skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.