nix: the shipped collector aborts on a thread-exit race, because the patch for it reached only sanitized builds · Issue #101 · nixidae/nixidae · GitHub
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
nix: the shipped collector aborts on a thread-exit race, because the patch for it reached only sanitized builds #101
The concurrency soak aborts in a plain dev shell, with no sanitizer, at a
rate near two runs in five. The message comes from Boehm:
pthread_kill failed at suspend: errcode= 22
Fatal Python error: Aborted
It arrives straight after test_an_operation_that_runs_a_nix_thread_pool_still_completes, which is the
test that starts and then joins a pool of Nix threads.
Errcode 22 is EINVAL. Boehm looks a thread up in GC_threads, and the
thread exits before the pthread_kill that follows. POSIX leaves the result
of a signal to a dead thread undefined, and this glibc answers EINVAL where
Boehm tolerates ESRCH alone. So Boehm aborts on a race that the soak makes
common: a thread pool that ends beside an evaluator that allocates.
The patch already lived here, and it reached the wrong builds
nix/patches/boehmgc-tolerate-suspend-thread-exit-race.patch teaches GC_suspend_thread to accept EINVAL beside ESRCH. nix/sanitizer.nix
applied the patch inside sanitizeBoehmGC.
That function runs only when a sanitizer is selected. The plain build, the
build that ships and the build that every dev shell uses, got the collector
with the defect still in it. The sanitized builds, which nobody ships, got the
correction.
Measurement
Fifteen runs of one command per row, five seeds, same machine:
The SIGSEGV is issue #99, and it is a different defect. It survives the patch,
as expected, and it faults in nix::ExprVar::eval in both columns.
The fix
nix/boehmgc.nix holds patchBoehmGC, and default.nix applies it to every
scope that has a collector. sanitizeBoehmGC keeps the sanitizer flags alone.
A sanitized build gets the patch through the same path as every other build,
so the two cannot separate again.
Acceptance
15 soak runs in a plain dev shell, 0 aborts.
nix eval over the four scopes shows the patch present in plain, tsan
and ubsan, and absent from nogc, which has no collector to patch.
Issue #98 is a different abort, under TSAN alone, that reports Signals delivery fails constantly at GC #N. That one is Boehm giving up
after 150 resends because TSAN intercepts signal delivery. This one is an EINVAL from a single pthread_kill, and it needs no sanitizer.
The verification hunt finished at 30 runs, and not 15: 0 aborts in 30. At the pre-patch rate of 6 in 15, the probability of that is 0.6^30, near 2e-7. The one SIGSEGV in those 30 runs is #99, in nix::ExprVar::eval as before.
Same cause as #82: Boehm signalled a thread that had exited
GC_thr_init gives bdwgc's one static first_thread entry to whichever
thread reaches GC_INIT(), marks it DETACHED | MAIN_THREAD, and never
removes it. Session.open reached that call on a nix-store executor
thread, which exits when the session closes. GC_suspend_all then signals a
dead thread on every later collection.
Three outcomes of that one signal, and each has its own issue: an EINVAL
return (#72), a fault inside pthread_kill (#53), and a lost signal that
makes resend_lost_signals abort after 150 tries (#69).
nix::initGC now runs while the extension module imports, so the entry names
the process main thread. #82 carries the core dump, the bdwgc reasoning, and
the measurement.
Activity
fix(nix): give every build with a collector the suspend-race patch
Lillecarl commentedon Aug 4, 2026
The verification hunt finished at 30 runs, and not 15: 0 aborts in 30. At the pre-patch rate of 6 in 15, the probability of that is
0.6^30, near 2e-7. The one SIGSEGV in those 30 runs is #99, innix::ExprVar::evalas before.fix(bindings): take over a stale Boehm registration, and give the reason
fix(bindings): start the collector at import, on a thread that never …
Lillecarl commentedon Aug 4, 2026
Same cause as #82: Boehm signalled a thread that had exited
GC_thr_initgives bdwgc's one staticfirst_threadentry to whicheverthread reaches
GC_INIT(), marks itDETACHED | MAIN_THREAD, and neverremoves it.
Session.openreached that call on anix-storeexecutorthread, which exits when the session closes.
GC_suspend_allthen signals adead thread on every later collection.
Three outcomes of that one signal, and each has its own issue: an
EINVALreturn (#72), a fault inside
pthread_kill(#53), and a lost signal thatmakes
resend_lost_signalsabort after 150 tries (#69).nix::initGCnow runs while the extension module imports, so the entry namesthe process main thread. #82 carries the core dump, the bdwgc reasoning, and
the measurement.
fix(bindings): own the collector's thread in C++, and start it lazily
ci(tsan): let one collector abort fail the soak, now that none happen
fix(nanopynix): give the evaluator a collector, and fork a contract p…
docs(collector): exclude the unregistered-displacement cause of #70
fix(nix): give every build with a collector the suspend-race patch
fix(bindings): take over a stale Boehm registration, and give the reason
fix(bindings): start the collector at import, on a thread that never …
fix(bindings): own the collector's thread in C++, and start it lazily
ci(tsan): let one collector abort fail the soak, now that none happen
fix(nanopynix): give the evaluator a collector, and fork a contract p…
docs(collector): exclude the unregistered-displacement cause of #70