What is Heisenbug?
A heisenbug is a software defect that seems to change its behavior or disappear when you attempt to observe or debug it, named, with a nod to the Heisenberg uncertainty principle, because the act of measurement alters the result.
Free to start · 7-day trial on paid plans
In depth.
Heisenbugs are a notorious category of hard-to-reproduce defects. The classic symptom: a bug occurs in production or normal runs, but the moment you add logging, attach a debugger, or run in a slower or instrumented mode, it vanishes, only to return when you stop looking. The reason is usually that the bug depends on timing, ordering, or uninitialized state, and the act of observing changes that timing.
Common causes include race conditions and concurrency issues (debugging slows things down and hides the race), uninitialized memory or variables (debug builds may zero memory that release builds leave with garbage), and optimization differences between debug and release builds. Because adding observation changes the conditions, the normal debug-and-reproduce loop breaks down.
Strategies to catch heisenbugs lean on low-impact observation and reasoning: lightweight logging that does not alter timing, capturing state without pausing, stress and concurrency testing to make the underlying race more frequent, code review and reasoning about thread safety and initialization, and tools like thread/memory sanitizers. The deeper point for testers is that some of the worst bugs resist direct observation, so finding them requires indirect evidence and an understanding of timing, concurrency, and state.
Why interviewers ask about this.
The heisenbug is a memorable concept that signals real debugging depth. Explaining why a bug can vanish under observation (timing, concurrency, uninitialized state) and how to catch it (low-impact logging, stress/concurrency testing, sanitizers) shows you understand the hardest end of defect investigation.
Example scenario.
A crash happens occasionally in production, but never when a developer runs the app under a debugger. It is a heisenbug: a race condition that the debugger's slower timing hides. The team reproduces it by stress-testing concurrency and adding a thread sanitizer, which surfaces the data race that direct debugging could not.
Interview tip.
Define a heisenbug as a defect that changes or disappears when you try to observe it, typically caused by timing, concurrency, or uninitialized state. Explain why observation alters the outcome, and give strategies: low-impact logging, stress/concurrency testing to amplify the race, and tools like thread or memory sanitizers.
Frequently asked questions.
Why does a heisenbug disappear when you debug it?
Because the bug depends on timing, ordering, or uninitialized state, and observing it changes those conditions. Adding logging or a debugger slows execution and alters timing (hiding a race condition), and debug builds may initialize memory that release builds leave with garbage, so the conditions that triggered the bug no longer occur.
How do you catch a heisenbug?
Use low-impact observation that does not alter timing (lightweight logging, capturing state without pausing), run stress and concurrency tests to make the underlying race occur more often, reason about thread safety and initialization through code review, and use tools like thread and memory sanitizers that detect races and uninitialized access.
Related Terms
Explore related glossary terms to deepen your understanding.
Related Resources
Dive deeper with these related interview prep pages.
Free QA career tools, no account needed
Instant and private, everything runs in your browser. Try them before you sign up.
QA Resume Checker
Instant 0-100 score on automation keywords, impact, and ATS formatting.
QA Cover Letter Generator
A tailored 3-paragraph QA cover letter from your resume and a job post.
QA Application Tracker
Drag-and-drop kanban to track every QA application from Applied to Offer.
QA Take-Home Test Generator
A realistic take-home assignment with a scenario, tasks, and a rubric.
QA LinkedIn Headline Generator
A recruiter-searchable headline, About section, and skills list.
QA STAR Story Builder
Structure a QA behavioral answer with the STAR method and instant checks.
QA Bug Report Generator
Build a clean, reproducible bug report for Markdown, Jira, or plain text.
Boundary Value Analysis Generator
Generate boundary value and equivalence partitioning test cases from a range.
QA Metrics Calculator
Calculate DRE, defect leakage, defect density, and pass rate with interpretation.
QA Test Plan Generator
Build a structured test plan (scope, approach, criteria, risks) in Markdown.
Ready to Ace Your QA Interview?
Practice explaining heisenbug and other key concepts with our AI interviewer.
Join 1,200+ QA engineers already practicing with AssertHired.
Start your free QA interview