Other meanings of Heisenbug
Software Engineering
A Heisenbug is a software bug that changes or disappears when it is observed or debugged, named after Werner Heisenberg's uncertainty principle. The term is used in computer science to describe defects that are difficult to reproduce because the act of debugging alters the system's behavior.
A Heisenbug is a software defect that evades detection because the act of debugging changes its behavior. The term was coined in the 1970s, likely at Bell Labs, as a playful reference to Werner Heisenberg's uncertainty principle, which states that observing a quantum system inevitably alters it. In software, this occurs when debugging tools (e.g., debuggers, logging, or instrumentation) modify timing, memory layout, or state, causing the bug to vanish or morph.
The term is part of a family of bug-related puns, including Bohr bug (a bug that is deterministic and easy to find) and mandelbug (a bug whose behavior is chaotic and complex). Heisenbugs are often associated with race conditions, uninitialized memory, and timing-dependent code.
Heisenbugs typically arise from non-deterministic behavior. Race conditions are a prime example: when multiple threads access shared data without proper synchronization, the outcome depends on timing. Adding a debugger or print statement can change thread scheduling, hiding the race. Similarly, reading uninitialized memory may yield different values depending on what was previously on the stack or heap, and debugging can alter that memory.
Another cause is optimization: compiling with debug symbols or disabling optimizations can change the code's execution order or eliminate certain behaviors. For instance, a bug that only appears with optimized code may vanish when compiled with -O0 for debugging. Time-sensitive bugs, such as those involving network timeouts or real-time constraints, also exhibit Heisenbug behavior because debugging introduces delays.
Debugging Heisenbugs requires techniques that minimize interference. One approach is to use core dumps or post-mortem debugging, which capture the state at the moment of failure without altering execution. Another is to use logging that is asynchronous or buffered to reduce timing impact. Reproducing the bug in a controlled environment, such as a virtual machine with deterministic replay, can also help.
Static analysis and formal methods can identify potential Heisenbugs without executing the code. For race conditions, tools like ThreadSanitizer or Helgrind can detect data races without the need for reproduction. In some cases, adding deliberate delays or using fault injection can force the bug to manifest. The goal is to observe the system without perturbing it, a principle reminiscent of quantum measurement.
The term Heisenbug has inspired related concepts: a Bohr bug is deterministic and easily found, while a mandelbug is complex and chaotic, named after Benoît Mandelbrot. A schrödinbug is a bug that never manifests until someone reads the source code and realizes it should, at which point it appears. These terms are used humorously in software engineering culture.
Heisenbugs are not limited to software; they can occur in hardware and other systems. For example, a hardware bug that only appears when a logic analyzer is attached is analogous. In physics, the observer effect is a related but distinct concept from the uncertainty principle. The term has also been used in other fields, such as psychology, to describe how measuring a behavior can change it.
The term is a pun on Heisenberg's uncertainty principle, which states that observing a system changes it.
Help improve the encyclopedia. Reports go straight to the site manager.