Repository navigation
Description
The soak found a Value * that is not a Value *. UBSAN caught it, and the
process then died with SIGSEGV.
What happened
Run 30927089860,
job test-ubsan-nix_2_35
(92052107768),
commit c1f2a1b6 on ci-develop.
UBSAN reported the same address seven times, up the whole force chain, and
the last report is an SSE load that faults:
../eval.cc:1418:21: runtime error: reference binding to misaligned address 0x000000007b82 for type 'struct Value', which requires 16 byte alignment
../include/nix/expr/eval-inline.hh:98:18: runtime error: member call on misaligned address 0x000000007b82 for type 'struct Value'
../include/nix/expr/value.hh:1240:27: runtime error: member call on misaligned address 0x000000007b82
../include/nix/expr/value.hh:1211:33: runtime error: member access within misaligned address 0x000000007b82
../include/nix/expr/value.hh:1211:33: runtime error: member call on misaligned address 0x000000007b82 for type 'const struct ValueStorage'
../include/nix/expr/value.hh:828:38: runtime error: member call on misaligned address 0x000000007b82 for type 'const struct ValueStorage'
../include/nix/expr/value.hh:706:37: runtime error: member access within misaligned address 0x000000007b82
.../include/emmintrin.h:701:11: runtime error: load of misaligned address 0x000000007b82 for type 'const __m128i'
Fatal Python error: Segmentation fault
0x7b82 is 31618. It is not a heap address, and UBSAN says
<memory cannot be printed> for it. So a Value * carried a small integer,
and eval.cc:1418 bound a reference to it.
What the process was doing
Three things at once, which is what makes this report worth more than the
earlier ones:
| thread | frame |
|---|---|
nix-eval_0 (crashing) |
CoreEvalState.repl_process_line |
nix-eval_0 (another) |
CoreEvalState.eval_string |
nanopynix (main) |
EvalSession.close -> NixThreadExecutor.shutdown (_nix_executor.py:430) |
The main thread was tearing an evaluator down while two other evaluators
evaluated. The teardown came from
test_deep_conversion_of_a_true_cycle_raises_instead_of_crashing, through
soak.py:516.
A teardown that runs beside an evaluation is the new fact. No earlier
report of this corruption had one, and the destructor of EvalState is the
one operation this repository lets leave its own thread (see the thread
confinement rule that #59 added). That makes it the first thing to look at,
and not a conclusion.
Rate
test-ubsan-nix_2_35 ran three times on ci-develop with the soak present:
runs 30916818149 and 30920512961 passed, and 30927089860 failed. The soak
deals tests to lanes from a seed, so the schedule differs between runs.
What this is not
This is not the Boehm stop-the-world abort of nixidae/nanopynix#69. That one exits 134 with
Signals delivery fails constantly at GC nixidae/nixidae#30, reports nothing, and has a
correction. This one is a real memory error, with a report and a signal.
It is the same family as the intermittent corruption that
test_inproc_parallel_batch_builds_use_multiple_store_workers shows on
GitHub runners: a value seen in a state it cannot be in, only under
concurrent evaluators, never locally. Those forms were a SIGSEGV in
nix::ExprVar::maybeThunk, an attrset that lost its type attribute, and
an InfiniteRecursionError on nixpkgs code that does not recurse.
Acceptance criteria
- Name the operation that makes a
Value *a small integer. - Say whether a concurrent
EvalSession.closeis sufficient to cause it, or
only makes it visible. - Add a test that fails before the correction. The soak is the reproducer of
last resort, and it is not a test.
Notes for whoever takes this
libexpr/eval-gc.cc calls GC_set_no_dls(1) and
GC_set_all_interior_pointers(0). Both make an embedding more likely to
lose a value than the Nix CLI is.
Already excluded by earlier work on the same family, so do not repeat them:
unregistered store threads (libstore never touches the Boehm heap), shared
mutable globals in the eval hot path (one Counter nrThunks), unrooted GC
pointers in the bindings (PyValue holds a nix::RootValue), and
EvalState's own GC data (Nix roots it with traceable_allocator).
Activity
Lillecarl commentedon Aug 4, 2026
It reproduces with no sanitizer, and the close hypothesis is wrong
Run 30931403310,
job
test-daemon-nix_2_34(92066746861),
commit
682cfb27. This is a plain job: no ASAN, no UBSAN, no TSAN. Theprocess died with signal 11, and the step exited 139.
The thread layout is the same as the UBSAN report above:
nix-eval_0(crashing)CoreEvalState.repl_process_linenix-eval_0(another)CoreEvalState.eval_stringnanopynix (main)Session._forward_logs->LogCollector.take_droppedThe C stack names the faulting frame:
nix::ExprVar::evalis the same place the 2026-07-28 SIGSEGV landed, intest_inproc_parallel_batch_builds_use_multiple_store_workers. That reportnamed
nix::ExprVar::maybeThunk, its neighbour. So the soak reproduces theold intermittent corruption, and it does so without instrumentation.
The concurrent
EvalSession.closeis not necessary. I wrote above thata teardown beside an evaluation was the new fact and the first thing to look
at. This occurrence has no teardown: the main thread is forwarding log
records. Two evaluators evaluating at once is sufficient. Withdraw that
lead.
What is now available that was not before
NANOPYNIX_CORE_DEBUG=1produced a core, and the job ran gdb over it:Three Boehm marker threads were parked in
GC_help_markerat the time. Thatis
PARALLEL_MARK: the collector was not in a stop-the-world pass, themarkers were idle and waiting.
Effect on the branch that found it
tests/nanopynix/test_concurrent_soak.pyis new, and it runs in the ordinarymatrix as well as under the sanitizers. So this defect, which used to appear
about once in a set of full runs, now has a test that reaches for it every
run. Until this issue is closed,
test-local-*andtest-daemon-*can gored on any commit, and the cause will be this and not that commit.
test(tsan): keep the soak honest about what it can report
Lillecarl commentedon Aug 4, 2026
It reproduces in a plain dev shell, and one run corrupted a value without crashing
The soak driver reproduces this with no sanitizer and no CI runner. The
command is one plain invocation, repeated over five seeds:
Fifteen such runs gave 4 SIGSEGVs. Every one of them faults in the same
frame this issue already names:
with three other
nix-eval_0threads live beside it.One run failed without crashing, and that run is worth more than the four
that crashed. In lane 3, beside 40 other tests,
test_a_cancelled_interruptible_operation_frees_the_evaluatorraised:The caret points at the lambda. Nix says the value at index 72679 is
x: x, and not the integer that applyingx: xproduces.That expression cannot produce a function.
genList f nstoresf iatindex
i, so every element forces to an integer. Checked directly, on thesame build:
So a
Valueanswered "function" where an integer was written into it. Thatis type confusion, and not a crash — the same shape as the attrset that
reached
lib.isDerivationhaving lost itstypeattribute, which this issuealready records.
Note the two nested "list element" frames as well.
genListbuilds one flatlist, so there is no second level for the evaluator to be inside.
Why the non-fatal manifestation is the better lead
A segfault gives a faulting address and a stack, and the process is gone. This
gives a live process that keeps running, a Nix error with a source
position, and an index into a list. Whatever wrote the wrong thing into a
Valuewrote it at a place that stays reachable, and the process survived toreport it.
An abort shared these runs. It is a different defect, and it is fixed
Six of the same fifteen runs ended in SIGABRT and not SIGSEGV, with
straight after
test_an_operation_that_runs_a_nix_thread_pool_still_completes.That is Boehm signalling a thread that already exited. This repository
carried the patch for it, but applied the patch to the sanitized builds
alone, so the collector that ships was the one collector still without it.
nix/boehmgc.nixnow applies the patch to every build with a collector.Fifteen runs of the identical command after that change:
The abort is gone, and the crash of this issue remains — in
ExprVar::evalagain. So the abort was never part of this issue, and its removal makes what
is left attributable.
fix(nix): give every build with a collector the suspend-race patch
Lillecarl commentedon Aug 4, 2026
The collector is in the causal path, and the rate says so
Two arms of the same command, five seeds each, on the same machine, with the
Boehm patch of #101 in place so the aborts do not confound the count:
GC_FREE_SPACE_DIVISOR=64GC_FREE_SPACE_DIVISORis Boehm's own knob for how much free space it keepsbefore it collects again. The default is 3, so 64 asks for far more
collections over the same work. Nothing else differs between the two arms:
same build, same seeds, same machine.
3% against 33%. Fisher's exact on those counts gives p near 0.002.
One run of the amplified arm ended in a lane timeout rather than a crash,
which is the price of collecting that often, and it is not a finding.
What that rules in, and what it rules out
A crash whose rate follows the collection rate is a crash that a collection
causes. The two shapes that fit are a live object that the collector cannot
see and therefore reclaims, and an object handed out twice. Both give the same
symptom: a
Valuethat holds something other than what was written into it,which is the type confusion in the comment above.
A plain data race does not fit. Collecting more often does not make two
threads write the same word more often, and ThreadSanitizer reports nothing:
test-tsan-nix_2_34,test-tsan-nix_2_35andtest-tsan-gitall pass withthe soak in them, in run 30940324091.
What is already excluded
nix-base-env-size.patchraisesboth containers to 512 and tests the bound, and it applies to every version
in the tree. The crash is measured with that patch in place.
gone: 0 aborts in 30 runs of the default arm.
PyValue::evalStatecallsPyEvalState::checkThreadand every accessor funnels through it, so a valuecannot be read or allocated from a thread the collector does not know.
The next measurement
GC_DONT_GC=1is the other half of the argument. Five runs of the defaultarm with it gave 0 crashes, which points the same way, and the arm needs
repeating: an unrelated rebuild interrupted it after the first round.
Lillecarl commentedon Aug 4, 2026
The third arm closes the argument: no collection, no crash
GC_DONT_GC=1turns Boehm's collection off for the life of the process(
misc.creads the variable at init and setsGC_dont_gc). Twenty runs ofthe same command, the same five seeds, the same build:
GC_DONT_GC=1GC_FREE_SPACE_DIVISOR=64The rate is monotone in how often the collector runs, across a factor of
about 20 in each direction. A crash that stops when collection stops, and
gets 10 times more likely when collection gets more frequent, is a crash a
collection causes.
That leaves the two shapes named in the comment above: a live object the
collector cannot see and reclaims, or an object handed out twice. Both give a
Valueholding what nobody wrote into it.What this does not say
It does not say the bug is in Boehm. A missing root is a defect of the
program that owns the pointer, and the collector is only the thing that acts
on it. The next step is to find what holds a
Valuein memory the collectordoes not scan.
Two candidates are already excluded by reading, and are written down so the
next reader does not repeat them:
traceable_allocatorisGC_MALLOC_UNCOLLECTABLEtoallocate and
GC_FREEto release (bdwgcgc_allocator.h), anduncollectable memory is still scanned.
allocRootValue,baseEnvP,ValueVector,ValueMapand the file caches all use it.~PyValueon a foreign thread.GC_freetakes the allocation lock onboth of its paths and touches no thread-local state, so releasing a root
from an unregistered thread is safe.
Lillecarl commentedon Aug 4, 2026
One more sighting, away from the four-evaluator test
The full local suite died once at ~110 s, in
tests/nanopynix/rpc/test_log_backpressure.py,with two
nix-eval_0threads live:So the type confusion is not tied to the four-evaluator test. Two concurrent
evaluators are enough, and the crashing frame is the same shape: a
Valueread as the wrong type inside
eval.Rate, so far, on this machine: 1 crash in 5 full-suite runs. Four further
runs of the same suite, on the same build, passed with 2126 tests each, and
the CI matrix of 23 jobs is green. So this is not a reliable reproduction, and
it did not follow any change of that day: three full-suite runs on the build
before it also passed.
Recorded here because the earlier note says "the four-evaluator test", and
that is too narrow.
ci(gc): add a temporary soak workflow for issue #70
ci(gc): add a temporary soak workflow for issue #70
ci: add a generic, parameterized experiment runner
Lillecarl commentedon Aug 5, 2026
The soak did not reproduce #99, and it found the mechanism anyway
CI run 30966905346, three arms of five runs each, on
gc-soakat 9b28f36d.GC_set_all_interior_pointers(1)GC_FREE_SPACE_DIVISOR=64The
interiorarm settles nothing. #99 did not appear in the control armeither, so the soak measured no rate to compare against. The displacement
class stays open.
The one failure has a different signature, and it names the cause
gc-soak (4, amplified), intest_string_arg_with_context_is_realised. It isnot a type confusion. It is
SIGABRTinside the allocator, on the mainthread. Resolved against the exact
libgc.so.1of that job:The abort message is at
.rodata0x29ca0, and it readsCollecting from unknown thread. That isGC_push_all_stacks, inpthread_stop_world.c:918:Why the main thread is unknown to Boehm
tests/conftest.py:439builds the evaluator directly:That call runs on the pytest main thread, and so does every
eval_stringonthe result. Only
NixThreadExecutorcallsenter_evaluator_thread, which isthe one place that calls
GC_register_my_thread. The main thread thereforeevaluates Nix, allocates Nix values, and is absent from Boehm's thread
table.
test_the_main_thread_does_not_own_the_collectoralready assertsthis, and it passes.
One cause, two faces
GC_push_all_stackswalks the registered threads, pushes the stack of eachone as a root, and aborts only when the calling thread is not among them. A
thread that is absent and is not the caller is never visited, and its stack is
never scanned. Two outcomes follow, and the trigger picks between them:
found_mestaysfalse, and Boehm aborts. This is the failure above, and the amplified arm
makes it frequent because it makes every collection frequent.
thread holds values.
found_meis true, so there is no abort. The mainthread is not suspended and its stack is not scanned, so a value that only
that stack refers to is unreachable, and the collector frees it. The
next read of that pointer gives whatever took the memory.
Outcome 2 is the symptom of this issue: a
Valuepointer that reads as asmall integer. The rate follows the collection rate, which is the measurement
already recorded in
docs/collector-and-threads.md: 0 in 20 withGC_DONT_GC=1, 1 in 30 by default, 5 in 15 with the amplified divisor.I have not yet proven that outcome 2 causes this issue. The mechanism fits
every measurement so far, and it is testable: register the thread that builds
an
EvalState, and the rate must go to zero.Next
Register the calling thread with Boehm when an
EvalStateis constructed, sothat a caller that never touches the executor is safe. This is the other half
of the argument that moved the collector's owner into C++ (7f6ef4e7): owning
the collector's thread there makes a direct
EvalStatecaller safe from thefirst_threadbug, and this makes the same caller safe from the root-scanningbug. The registration needs to be released at thread exit, or it becomes the
stale entry of #101 and #82.
fix(bindings): register the thread that builds an evaluator with Boehm
fix(bindings): register the thread that builds an evaluator with Boehm
ci(gc): retire the soak workflow, now that the runner covers it
ci: refuse an abbreviated sha as the experiment ref
53 remaining items
fix(bindings): give the GC thread debug line a pid
docs(collector): count the crashes, and not every failed run
feat(nix): pair the pushed stacks against the threads we registered
feat(bindings): measure the stack bound the collector recorded
docs(collector): say why the evaluator allocator is not the defect
docs(collector): read the crash out of a core dump
feat(bindings): refuse a value pointer that keeps its discriminator bits
fix(bindings): root the REPL environment, which nothing held
fix(bindings): name traceable_allocator where it really lives
test(nanopynix): skip the REPL environment tests without a collector
chore(bindings): remove the interior-pointer differential, which #70 …
ci(gc): add a temporary soak workflow for issue #70