Heisenbug¶
Category: Hazards · Status: stub
One line: A bug that disappears or changes when you look for it — adding a print, attaching a debugger or changing the optimizer shifts the timing it depends on.
Also called: flaky concurrency bug.
How it connects¶
flowchart LR
n_deterministic_testing["Deterministic scheduling for tests"]
n_heisenbug["Heisenbug"]
n_nondeterminism["Nondeterminism"]
n_race_condition["Race condition"]
n_deterministic_testing -->|prevents| n_heisenbug
n_nondeterminism -->|can cause| n_heisenbug
n_race_condition -->|can cause| n_heisenbug
classDef center stroke-width:3px
class n_heisenbug center
classDef outside stroke-dasharray: 4 3
class n_deterministic_testing,n_nondeterminism,n_race_condition outside
- Is prevented by: Deterministic scheduling for tests
- Can be caused by: Nondeterminism, Race condition
- See also: Deterministic scheduling for tests, Race detector
In each language¶
| Rust | loom ↗ deterministically explores the possible execution permutations instead of relying on random runs |
| Go | testing/synctest ↗, new in Go 1.25 ↗, runs a test in a bubble whose fake clock advances only when every goroutine in it is durably blocked |
| Elsewhere | rr ↗ records a failing run once and replays it deterministically; its chaos mode makes intermittent bugs more reproducible |
Where to read more¶
- In a sibling library: Go:
synctestmakes time virtual ↗ - In a sibling library: Go:
synctest.Waitinstead of a sleep ↗ - Notes: heisenbug ↗
- Reference: Wikipedia: Heisenbug ↗