Repository navigation
Description
What
pytest tests/nanopynix/inproc kills the process. The dev shell build has the
collector, and this is not the no-collector work of #76.
scripts/run-tests.sh --wait tests/nanopynix/inproc
[pytest-agent] 10s pass=9 fail=0 done=9 tot=103 cur=tests/nanopynix/inproc/test_inproc.py::test_a_collected_value_gives_its_root_back_to_the_collector[local]
Fatal Python error: Aborted
Current thread 0x00007fffc3fff6c0 [nix-eval_0] (most recent call first):
File "tests/nanopynix/inproc/test_inproc.py", line 206 in _collect_and_read_non_gc_bytes
File "nanopynix/src/nanopynix/inproc/_impl.py", line 193 in _run_with_log_context
File "nanopynix/src/nanopynix/_core/_nix_executor.py", line 98 in _run_interruptible
Line 206 is nanopynix_expr._gc_collect(). The collection runs on the
evaluator thread, which is the documented rule for that probe.
Evidence
The process dies with SIGABRT or with SIGSEGV. The signal is not stable,
and the point of death moves with the selection of tests. A signal that
changes between two runs of the same command is a sign of memory corruption,
and a forced collection is what finds it.
| run | selection | result | last test that finished |
|---|---|---|---|
| 1163 | tests/nanopynix/inproc |
SIGABRT | test_a_collected_value_releases_its_nix_root |
| 1159 | tests/nanopynix/inproc |
SIGSEGV | test_a_collected_value_releases_its_nix_root |
| 1158 | tests/meta tests/nanopynix/inproc tests/nanopynix/bindings ... |
SIGABRT | test_inproc_value_build_raises_on_build_failure |
| 1161 | tests/nanopynix/inproc/test_inproc.py -k collected_value |
2 passed | — |
The two collector tests pass when they run alone. They need the state that the
tests before them leave behind.
Memory is not the cause. The transient unit peaked at 437 MB.
What is ruled out
This is not the work of #76, and it is not the base environment patch. The
same command was run again at two earlier commits, with no other change:
f712fce5, which is the commit before the change that found this. It dies
the same way, at the same test.5fdfb3f1, which is the commit before2395efab("give the base
environment room, and check the bound"). It dies the same way. That patch
changesBASE_ENV_SIZEandbuildBindingsin the shipping build with the
collector, so it was the first suspect, and it is not the cause.
Why this matters more than one red run
The suite passes in CI today, so the ordering that produces this does not
occur there. A corruption that a forced collection finds is a corruption that
an ordinary evaluation can also find, and the suite gives it no other place to
report.
test_a_collected_value_gives_its_root_back_to_the_collector is the only
caller of _gc_collect, so it is the only test that would ever say so.
Acceptance criteria
- The command above completes, and the result does not depend on the order of
the tests before it. - The root cause is named. A change that only reorders the tests, or that
removes the forced collection, is not a repair.
Tests
pytest tests/nanopynix/inprocin the dev shell, as a whole directory and
not as one file.- The two collector tests keep their forced collection.
Activity
Lillecarl commentedon Aug 4, 2026
A selection that crashes every time, in 48 seconds
The issue records that the point of death moves with the selection. One
selection does not move, and it is short:
Six runs, one after another, on
ci-developatabc3da69with no localchange:
test_a_collected_value_releases_its_nix_root[local]Every one of the six dies at the same place: the test after that one is
test_a_collected_value_gives_its_root_back_to_the_collector, which is the_gc_collect()probe this issue already names.tests/nanopynix/inprocon its own passes in the same shell, 101 passed. Sothe two logging modules in front of it are what makes the crash certain, and
they are what a reader should start from.
One earlier run of the same four paths passed, straight after the dev shell
rebuilt. That is the only pass seen, against 6 failures in a row afterwards,
so treat the selection as reliable rather than certain.
Why this is worth writing down
The reproduction in the issue needs the whole of
tests/nanopynix/inprocandgives a different signal each time. This one is 48 seconds, gives SIGSEGV
every time, and stops at one named test. That is enough to bisect the
selection, to run it under a sanitizer, and to test a hypothesis in a minute
rather than in an afternoon.
How it was found, and what it is not
It arrived as the failure of a change to the logger (issue #95). The control
is the same command with that change reverted and the extension rebuilt, and
it is the table above: the baseline crashes 6 times in 6. So the logger change
is not the cause, and this is the defect the issue already tracks.
Lillecarl commentedon Aug 4, 2026
Where it faults:
pthread_kill, inside Boehm's stop-the-worldThe reproduction above, under gdb.
faulthandlerprints nothing here, becausethe signal arrives inside a libc call that never returns, so gdb is what
gives the frame:
GC_suspend_allwalksGC_threadsand signals each registered thread. Thefault is the
pthread_killitself: glibc reads the thread descriptor to getthe tid, and the memory it reads is not there.
This is the same call site as #101. That issue is
pthread_kill failed at suspend: errcode= 22, anEINVALreturn from thesame line. Here glibc does not get as far as returning an errno. So the two
issues are one signal site with two outcomes, and the patch that widens
Boehm's tolerance to
EINVALcannot help this one: there is no return valueto tolerate.
What the registration bookkeeping says, and what it rules out
NANOPYNIX_GC_THREAD_DEBUG=1withNANOPYNIX_GC_THREAD_DEBUG_FILEset,over one crashing run:
17 distinct operating-system thread ids. Every one of them enters once and
exits once, except the last, which is the thread that called
_gc_collectand died in it. And
enter_evaluator_thread:duplicateappears zero times.So at the moment of the collection, Boehm knows exactly one thread, and that
thread is the caller.
GC_suspend_allskips the caller(
THREAD_EQUAL(p->id, self)), and it skips an entry with theFINISHEDflag.It should therefore signal nobody.
That excludes the explanations that do not need corruption:
pthread_t. That would show asGC_DUPLICATEat the nextGC_register_my_thread, andenter_evaluator_threadlogs that case. It never fired.pair, per thread id.
What is left is that
GC_threadsitself holds something it should not --Boehm's own bookkeeping, walked with the allocation lock held, giving a
pwhose
idis not a live thread.GC_register_my_threadmarks a threadDETACHED, soGC_unregister_my_threadcallsGC_delete_thread, whichfrees the
GC_threadstruct throughGC_INTERNAL_FREE. A freed struct thatsomething else wrote over fits this exactly.
That is heap corruption, which is what this issue says. The new part is that
the collection does not die in the mark phase over a corrupt
Value; it diesbefore marking starts, over Boehm's own thread table.
fix(bindings): take over a stale Boehm registration, and give the reason
Lillecarl commentedon Aug 4, 2026
The same condition also produces the abort of #98
The reproducer above was run four times against a collector built with
--enable-gc-assertions(and four times against an otherwise identicalcontrol, to show that the rebuild is not what matters):
dontStrip, patched--enable-gc-assertionsThe abort resolves to:
That is the
Signals delivery fails constantly at GC #Nabort of issue #98,in a plain dev shell with no sanitizer. So this issue, #98 and #101 are one
condition -- Boehm cannot suspend a thread it has in
GC_threads-- and thethree signals are only which way the timing falls.
GC_ASSERTIONSfires on nothing. Boehm's own invariants hold right up tothe signal, so its bookkeeping is not being corrupted in a way it can notice.
That is a point against "a stray write landed in
GC_threads", and a pointfor "the entry is intact and names a thread that is gone".
The next step is to read
GC_threadsat the moment of the fault. Theassertion build carries DWARF, so gdb can walk the table and compare it with
info threads. The run passes more often under gdb, so it needs a loop.fix(bindings): start the collector at import, on a thread that never …
Lillecarl commentedon Aug 4, 2026
Root cause: Boehm's
first_threadnamed a thread that had exitedA core dump gives the state directly.
GC_threadsheld two entries:0x778fcbfff6c0is not ininfo threads. Flags0x6isDETACHED | MAIN_THREAD, withFINISHEDclear, soGC_suspend_allsignalsit:
Why that entry exists
bdwgc has one statically allocated
GC_thread,first_thread.GC_thr_initgives it to whichever thread reachesGC_INIT()first, andmarks it
DETACHED | MAIN_THREAD.GC_delete_threadunlinksfirst_threadbut never frees it, and
first_thread_usedis never reset. Nothing removesthe entry at thread exit, because bdwgc installs its exit hook only for
threads that
GC_pthread_createmade.Session.openreachedGC_INIT()on anix-storeexecutor thread:inproc/_impl.pyrunsawait executor.run(self._init_nix), and_init_nixcalls
init_libexpr()->nix::initGC(). That pool has noenter/exit_evaluator_thread hooks, and it shuts down with the session. Every
later collection then signals a thread that is gone.
This is one condition with three outcomes
EINVAL, and Boehm aborts witherrcode= 22.pthread_killbefore it can return.resend_lost_signalsaborts after 150 tries.The earlier bookkeeping evidence stays true and is not contradicted: 17
enters, 17 exits, zero
GC_DUPLICATE. Our registrations were always balanced.The bad entry is the one bdwgc made for itself, which our hooks never see.
The fix, and the measurement
nix::initGCnow runs while the extension module imports, sofirst_threadis the process main thread, which lives as long as the process.
GC_INIT()runs onnix-storepool threadSame build, same selection, same machine:
One trap, for whoever reads this next
Moving only Boehm's own bring-up to import is worse than doing nothing. It
leaves
nix::initGCto callGC_set_all_interior_pointers(0)withGC_is_initializedalready true, which resets the valid offsets and runsGC_bl_init_no_interiors()over a heap that is in use. Four evaluators thenread a value as the wrong type, 6 runs in 6, where the unmodified build fails
0 in 6. Move the whole of
initGC, or none of it.fix(bindings): own the collector's thread in C++, and start it lazily
Lillecarl commentedon Aug 5, 2026
The crash no longer reproduces
The command of this issue, run 12 times in the dev shell on
e356c18a:The issue recorded SIGABRT or SIGSEGV in 3 runs of 4, on this same machine. Three of the 12 runs exited 1, and none of those is this defect: each is one assertion in
test_inproc_parallel_batch_builds_use_multiple_store_workers, which measures build dispatch timing. That test is a separate finding, and it gets its own issue.What corrected it
b1675f82and7f6ef4e7.nix::initGCreachedGC_INIT()on anix-storeexecutor thread, so bdwgc's one staticfirst_threadentry named a thread that the session later shut down.GC_suspend_allthen signalled a thread that was gone. The collector now comes up on an owner thread that parks and never returns.Both commits say
Refs nixidae/nixidae#82rather thanCloses, because the measurement above had not been made yet. It has now.What this does not close
The multi-evaluator corruption of #99 is a different fault. It lands in
nix::ExprVar::evalrather than inGC_suspend_allorpthread_kill, and it survives this fix -- run 30993492366 segfaulted in the concurrency soak one356c18a. #99 stays open and carries that record.Closes #82
fix(nanopynix): give the evaluator a collector, and fork a contract p…
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
fix(nanopynix): give the evaluator a collector, and fork a contract p…