Heisenbug

Heisenbug image
A Heisenbug is a type of software bug that seems to change its behaviour or even disappear when we try to investigate it. The name comes from the Heisenberg Uncertainty Principle in physics, which suggests that the act of observing something can affect the thing being observed. 

In practice, a Heisenbug might show up during normal execution but vanish as soon as you run the debugger, add logging, or try to reproduce it under controlled conditions. This can happen due to timing issues, memory corruption, uninitialized variables, or race conditions. 

For example, a program might crash randomly in production, but when you attach debugging tools, the additional processing changes the timing and the bug no longer appears. These bugs are some of the most frustrating to test because they are inconsistent and hard to pin down. 

Testing for Heisenbugs often involves running the software under varied conditions, using stress or load tests, and monitoring behaviour in real-world environments. Since direct observation sometimes hides the issue, testers rely on indirect signals such as logs, error reports, and monitoring tools to uncover them.
The term “Heisenbug” is a playful pun on the name of Werner Heisenberg, the well-known physicist who first asserted the observer effect of quantum mechanics.

“The observer effect (not to be confused with the uncertainty principle) is the fact that observing a situation or phenomenon necessarily changes it. Observer effects are especially prominent in physics where observation and uncertainty are fundamental aspects of modern quantum mechanics. Observer effects are well-known in fields other than physics, such as sociology, psychology, linguistics and computer science.” - The Observer Effect: IEEE publication, K. Baclawski et al.

An example would be checking your tyre pressure. By simply attaching a tyre gauge to the valve, you’re almost guaranteed to lose a very small amount of air. So simply by trying to read the tyre pressure, you’ll have changed the tyre pressure.

With this in mind, we can assume that the mere process of trying to reproduce a defect could change the behaviour of the code enough that the defect no longer occurs.

A software bug that disappears or alters its behavior when one attempts to probe or isolate it.
[from Heisenberg's Uncertainty Principle in quantum physics] A bug that disappears or alters its behavior when one attempts to probe or isolate it. (This usage is not even particularly fanciful; the use of a debugger sometimes alters a program's operating environment significantly enough that buggy code, such as that which relies on the values of uninitialized memory, behaves quite differently.) Antonym of {Bohr bug}; see also {mandelbug}, {schroedinbug}. In C, nine out of ten heisenbugs result from uninitialized auto variables, {fandango on core} phenomena (esp. lossage related to corruption of the malloc {arena}) or errors that {smash the stack}.

Heisenbug (noun)

A bug that dissappears when trying to debug it.

A Heisenbug is a bug that seems to disappear or change its behavior when you try to debug it. Heisenbugs have a reputation for acting in highly surprising ways. Any attempt to reproduce or debug a Heisenbug may result in its disappearance.

It is a nightmare for a developer to work on these kinds of issues since they know that this is going to be incredibly difficult to study the behavior and make sure that their fix covers all the cases.

The name of this bug is derived from the uncertainty principle conceived by Werner Heisenberg

Explore MoT
Don’t Be Left Behind: Close the Gap Between Test and Delivery image
Wed, 12 Nov
Align testing and delivery to reduce lead time and improve deployment frequency.
MoT Software Testing Essentials Certificate image
Boost your career in software testing with the MoT Software Testing Essentials Certificate. Learn essential skills, from basic testing techniques to advanced risk analysis, crafted by industry experts.
This Week in Quality image
Debrief the week in Quality via a community radio show hosted by Simon Tomes and members of the community
Subscribe to our newsletter
We'll keep you up to date on all the testing trends.