In computer programming jargon, a heisenbug is a software bug that seems to disappear or alter its behavior when one attempts to study it. The term is a pun on the name of Werner Heisenberg, the physicist who first asserted the observer effect of quantum mechanics, which states that the act of observing a system inevitably alters its state. In electronics the traditional term is probe effect, where attaching a test probe to a device changes its behavior.
Similar terms, such as bohrbug, mandelbug, hindenbug, and schrödinbug (see the section on related terms) have been occasionally proposed for other kinds of unusual software bugs, sometimes in jest; however, unlike the term heisenbug, they are not widely known or used.[original research?]
Heisenbugs occur because common attempts to debug a program, such as inserting output statements or running it in a debugger, usually modify the code, changing the memory addresses of variables and the timing of its execution.
One common example of a heisenbug is a bug that appears when the program is compiled with an optimizing compiler, but not when the same program is compiled without optimization (as is often done for the purpose of examining it with a debugger). While debugging, values that an optimized program would normally keep in registers are often pushed to main memory. This may affect, for instance, the result of floating-point comparisons, since the value in memory may have smaller range and accuracy than the value in the register. Similarly, Heisenbugs may be caused by side-effects in test expressions used in runtime assertions in languages such as C and C++, where the test expression is not evaluated when assertions are turned off in production code using the
Other common causes of heisenbugs are using the value of a non-initialized variable (which may change its address and/or initial value during debugging), or following an invalid pointer (which may point to a different place when debugging). Debuggers also commonly provide watches or other user interfaces that cause additional source code (such as property accessors) to be executed stealthily, which can, in turn, change the state of the program.
Time can also be a factor in heisenbugs, particularly with multi-threaded applications. Executing a program under control of a debugger can change the execution timing of the program as compared to normal execution. Time-sensitive bugs such as race conditions may not occur when the program is slowed down by single-stepping source lines in the debugger. This is particularly true when the behavior involves interaction with an entity not under the control of a debugger, such as when debugging network packet processing between two machines and only one is under debugger control.
Heisenbugs can be viewed as instances of the observer effect in information technology. Frustrated programmers may humorously blame a heisenbug on the phase of the moon, or (if it has occurred only once) may explain it away as a soft error due to alpha particles or cosmic rays affecting the hardware.
A mandelbug (named after Benoît Mandelbrot's fractal) is a bug whose causes are so complex it defies repair, or makes its behavior appear chaotic or even non-deterministic. It also refers to a bug that exhibits fractal behavior by revealing more bugs (the deeper a developer goes into the code to fix it the more bugs they find).
A schrödinbug or schroedinbug (named after Erwin Schrödinger and his thought experiment) is a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.
A higgs-bugson (named for the Higgs boson particle) is a bug that is predicted to exist based upon other observed conditions (most commonly, vaguely related log entries and anecdotal user reports) but is difficult, if not impossible, to artificially reproduce in a development or test environment. May also be used to reference a bug that is obvious in the code (mathematically proven), but which cannot be seen in execution (yet difficult or impossible to actually find in existence).
History of the term
The term was also used in 1985 by Jim Gray, in a paper about software failures (and is sometimes mistakenly attributed to him because of this publication) and also in 1986 by Jonathan Clark and Zhahai Stewart on the mailing list (later Usenet news group) comp.risks.
Heisenbugs are difficult to identify and fix; often attempting to resolve them leads to further unexpected behaviour. Because the problem manifests as the result of a separate, underpinning, bug behaviour can be hard to predict and analyse during debugging. Overall the number of heisenbugs identified should decrease as a piece of software matures.
- Cargo cult programming
- CHESS model checker—a tool for detecting and reproducing Heisenbugs (Windows)
- Memory debugger
- Jinx Debugger—a tool that automatically explores executions likely to expose Heisenbugs
- "The Jargon File: heisenbug".
- "The Jargon File: Mandelbug". Catb.org. Retrieved 2013-09-05.
- Raymond, Eric S.; The New Hacker's Dictionary, 3rd edition, 1996
- Clarke, Arthur C., The Ghost from the Grand Banks, Bantam Books, 1990
- "The Jargon File: Schroedinbug". Catb.org. Retrieved 2013-09-05.
- Raymond, Eric S.; The New Hacker's Dictionary, 3rd edition, 1996
- The following article investigates the various definitions of bohrbug, mandelbug and heisenbug proposed in the literature, as well as the statements made about the relationships between these fault types: Grottke, Michael; and Trivedi, Kishor S.; Software Faults, Software Aging and Software Rejuvenation, Journal of the Reliability Engineering Association of Japan, Vol. 27, No. 7, pp. 425–438, 2005.
- Grottke, Michael; and Trivedi, Kishor S.; Fighting Bugs: Remove, Retry, Replicate, and Rejuvenate, IEEE Computer vol. 40, no. 2 (February 2007), pp. 107–109
- A February 2012 Google Books search returns about 70 hits for "schroedinbug", 100 for "mandelbug", 400 for "bohrbug" or "heisenbug".
- "Java toString() override with initialization as a side effect" Archived 2014-12-30 at the Wayback Machine.
- CATB.org, "phase of the moon"
- Goshgarian, Gary; Exploring Language, HarperCollins College Publishers, 1995
- "Such transient software failures have been given the whimsical name 'Heisenbug' because they disappear when reexamined. By contrast, 'Bohrbugs' are good solid bugs." (IEEE Computer Group News, Volume 24, Numbers 7–12, 1991)
- "Hinden Bug".[better source needed]
- "New Programming Jargon".
- "Programming Jargon/Phrases You Should Know When Talking to Engineers".
- Gray, Jim (1985). "Why Do Computers Stop And What Can Be Done About It?". Technical Report 85.7. Tandem Computers.
- (16 December 1986) RISKS DIGEST 4.30 - (23 December 1986) RISKS DIGEST 4.34, moderated by Peter G. Neumann
- ""A Conversation with Bruce Lindsay", ACM Queue vol. 2, no. 8 - November 2004". Queue.acm.org. Retrieved 2013-09-05.
- Proceedings of the ACM SIGSOFT/SIGPLAN Software Engineering Symposium on High-Level Debugging, Pacific Grove, California, March 20–23, 1983, Association for Computing Machinery, 1983, Google Books search:
Also cited in LeBlanc, Richard J.; Robbins, Arnold D.; Event-Driven Monitoring of Distributed Programs, in Proceedings of the IEEE 5th International Conference on Distributed Computing Systems (ICDCS), IEEE Computer Society, Computer Society Press, 1985, pp. 515-522 Google Books search:
- P., Birman, Kenneth (2005). Reliable distributed systems : technologies, Web services, and applications. New York: Springer. ISBN 0387276017. OCLC 225378026.