Skip to main content


Home Heisenbug

Heisenbug

(also heisenbug)

Heisenbug definition

A heisenbug is a software bug that seems to change its behavior when observed — for example, when diagnostic tools are engaged or when a programmer attempts to debug it. The term is derived from the Heisenberg uncertainty principle in quantum mechanics, which claims that the act of observing a system can alter the system itself.

Heisenbugs are hard to deal with because traditional debugging techniques (which rely on controlled examination) can be counterproductive. To capture heisenbugs without disturbing the conditions under which they appear, developers have to resort to more advanced techniques, such as non-intrusive monitoring or sophisticated testing.

See also: secure software development lifecycle, bug fix, software bug, hindenbug, schrödinbug

Heisenbug incidence

The unusual behavior of heisenbugs is frequently a result of system concurrencies and faulty interdependencies. For example, in multi-threaded applications, a bug may result from a race condition where the precise order of operations among threads causes unexpected behavior. A debugger may slow down the execution or alter the timing, causing this race condition to disappear.

Detecting and resolving heisenbugs

  • Logging and tracing instead of directly interacting with the program through a debugger.
  • Using “record and replay” debugging tools which can capture the program's execution, allowing you to observe the exact sequence of events that led to the bug.
  • Using static analysis and code inspection to examine the underlying structure without running it.
  • Fuzz testing or stress testing to force the suspected heisenbug to appear.