Repository navigation
Description
What
Nix builds its evaluator without the Boehm collector when -Dgc=disabled sets
NIX_USE_BOEHMGC to 0. The evaluator then allocates and never releases.
Support that build for an RPC worker process, and recycle the process instead
of collecting inside it.
Why
A worker process can afford to leak. The RPC engine already gives each
worker its own process, and the operating system reclaims the memory of a
process that exits. A recycle policy replaces the collector. The in-process
engine cannot make that trade, so this is a worker capability and not a
project-wide switch.
AddressSanitizer needs it. libexpr refuses ASAN together with the
collector, in src/libexpr/meson.build:
bdw_gc_required = get_option('gc').disable_if(
'address' in get_option('b_sanitize'),
error_message : 'Building with Boehm GC and ASAN is not supported',
)#64 first built an ASAN variant that met this test only because the flag
arrived through NIX_CFLAGS_COMPILE, which meson does not read. That build
reported a tag read of a Value in value.hh on three Nix versions, which is
what a conservative collector produces when it frees an object that is still
live. The report was not usable as evidence. #64 now carries UBSan alone, and
a worker without the collector is the supported route to ASAN.
What the evaluator does without the collector
From eval-gc.hh and eval-inline.hh:
NIX_USE_BOEHMGC=1 |
=0 |
|
|---|---|---|
allocBytes(n) |
GC_MALLOC(n) |
calloc(n, 1) |
allocValue() |
GC_malloc_many batch, thread-local free list |
allocBytes(sizeof(Value)) |
allocEnv(1) |
the same batch | allocBytes(...) |
traceable_allocator, gc_allocator |
the Boehm allocators | std::allocator |
GC_MALLOC_ATOMIC |
Boehm | std::malloc |
gc, gc_cleanup base classes |
the Boehm classes | empty structs |
initGC() |
starts and tunes Boehm | does nothing |
eval.cc and eval.hh contain no free, no delete[] and no ~EvalMemory.
Nothing releases a Value or an Env in either mode.
Work
-
Guard the Boehm API in
nanopynix-bindings.nix_expr.cppcalls
GC_get_stack_base,GC_register_my_thread,GC_gcollectand the
counters with no#if NIX_USE_BOEHMGC. The headers are absent in a non-GC
build, so the extension does not compile today. Four functions carry all of
it:enter_evaluator_threadandexit_evaluator_threadbecome no-ops,
because there is no collector to register a thread with._gc_collectand
_gc_statsmust report that no collector is present. -
Add a non-GC variant to the package scope.
nix-expr.override { enableGC = false; }already evaluates. -
Choose how the worker gets that build. Two seams exist, and they are
not equal:- The stdio worker (
nanopynix-worker,_worker:_stdio_main) execs a
fresh process, so it can come from a non-GC environment, and the choice
can differ for each worker. - The forkserver preloads
nanopynix.rpc.worker._worker
(_pool.py:256), so each child inherits the extension that the
forkserver loaded. The forkserver is itself a fresh exec and copies the
environment once when it starts, so the choice is possible there, but it
is one choice for every worker of the process.
- The stdio worker (
-
Give the worker a recycle policy. A nixpkgs evaluation allocates
gigabytes, and no memory returns until the process exits. The trigger is
part of this work: a count of operations, a resident-size watermark, or
both. -
Add the ASAN variant on top.
nix/sanitizer.nixtakes aname, and
the file says at both relevant places whyaddressis absent today. A
non-GC worker removes that reason.
Acceptance criteria
nanopynix-bindingscompiles against a libexpr withNIX_USE_BOEHMGC=0.- An RPC worker runs the full RPC test suite against a non-GC build.
- A worker recycles on a stated trigger, and a caller does not observe the
recycle. - The in-process engine keeps the collector. A build with no collector is a
worker capability, andtests/nanopynix/test_engine_parity.pyrecords the
difference or shows that no difference reaches the API. - An ASAN job builds and runs against the non-GC worker, with no override of
the libexpr test quoted above.
Tests
- A test that proves
_gc_statsand_gc_collectreport the absence of a
collector rather than raising an unrelated error. - A test that drives a worker past its recycle trigger and proves that the
session continues, and that the process identity changed. - A memory test that proves the resident size of a worker returns after a
recycle. This is the test that says the design works. - The existing RPC suite, against the non-GC worker, in CI.
This blocks a decision already recorded
Q4 of docs/nanopynix/decisions.md asks whether the stdio worker has a
future, and its recommended default is to delete it: "It has an entry point,
no client, a stale docstring and no test." This issue is the client that it
lacks, and the stdio worker is the cleaner of the two seams in item 3. Decide
Q4 and this issue together, and do not action Q4 first.
Activity
feat(sanitizers): replace the ASAN variant with a UBSan one
Lillecarl commentedon Aug 3, 2026
Item 4 (the worker recycle policy) is now #79, and this issue keeps items 1, 2, 3 and 5.
The reason for the split is item 3, and it changes the answer this issue gives to it.
No Python code can pick between a build with the collector and one without.
multiprocessing_worker_with_backchannelpassesworker_service_factoryas theProcesstarget (grpclib-transports/src/grpclib_transports/multiprocessing.py:255). The forkserver child unpickles that target, and unpickling a module-level function imports its module — sonanopynix.rpc.worker._worker, and the extension under it, is loaded before any code of ours runs in the child. Preload only moves that import earlier. Andmultiprocessingkeeps one forkserver for each process, started from the parent'ssys.path. So the choice is made once, by the venv.Two facts behind that:
EvalStatecarries abaseEnvPmember only underNIX_USE_BOEHMGC(eval.hh:790), so the two builds are ABI-incompatible and one process must load exactly one of them, whichever mechanism selects it.eval-gc.hhaliasestraceable_allocatorandgc_allocatortostd::allocatorwhen the macro is 0, sonix::allocRootValue,PyValueand every other binding compile unchanged. Only#include <gc/gc.h>and the four functions this issue names break.So the non-GC build is a scope of
default.nix, beside-tsanand-ubsan, and not a runtime choice. Measured:-Dgc=disabledrebuildsnix-expr,nix-flakeand the bindings, and nothing else — three derivations.This also answers the last section of this issue. Q4 of
docs/nanopynix/decisions.mdasks whether the stdio worker has a future, and this issue said it would be the client that it lacks. It is not: the forkserver needed no change, and the stdio worker gained no client here.decisions.mdnow records that, and Q4 stands with its original recommendation.Acceptance criterion 4 needs no code, and here is why. It asks
tests/nanopynix/test_engine_parity.pyto record the difference between the engines or to show that none reaches the API. With one build for each closure, both engines lose the collector together, so there is no difference to record.feat(nix): build without the collector, so ASan runs the way Nix supp…
fix(nix): make the ASan build run, and stop pytest from hiding its re…
fix(nix): give the base environment room, and check the bound
ci(nogc): run the no-collector suite on every commit
Lillecarl commentedon Aug 4, 2026
The ASAN job finds a real memory defect. The proof is on #64, and it is a
stack-use-after-returnthat names the variable and the source line of the restored defect of #63. #89 records the one thing that still makes a red job ambiguous.Lillecarl commentedon Aug 5, 2026
Acceptance criterion 2 is met. Run 31016955422 ran the full suite against the non-GC build on all four versions --
test-nogc-nix_2_31,test-nogc-nix_2_34,test-nogc-nix_2_35andtest-nogc-git-- and all four passed.What unblocked it was the base environment overflow, now closed as #81. Criterion 1 is met with it, because the suite cannot run against a build that does not compile.
Criteria 3 and 5 stay open: the recycle policy is #79, and the ASAN job is #64 with #90 and #100 behind it.
One correction to the last section of this issue. It cites Q4 of
docs/nanopynix/decisions.md, whose recommended default is to delete the stdio worker. That default is withdrawn -- see #54 for the evidence.grpclib_transports.ssh.connect_ssh_stdiois its client, and it is the only SSH path that reaches a host running normal OpenSSH.Lillecarl commentedon Aug 7, 2026
Acceptance criterion 5 is now met
The comment above says: "Criteria 3 and 5 stay open: the recycle policy is
#79, and the ASAN job is #64 with #90 and #100 behind it."
#64 is closed, and #89, #90 and #100 are closed with it. Criterion 5 asks for
"an ASAN job that builds and runs against the non-GC worker, with no override
of the libexpr test". Run
31202037009
on
developpassestest-asan-git,test-asan-nix_2_31,test-asan-nix_2_34and
test-asan-nix_2_35, andtest-nogc-*on the same four versions.What is left
NIX_USE_BOEHMGC=0Only criterion 3 is left, and #79 owns it with its own acceptance criteria and
its own tests. This issue therefore holds no work of its own.
Refs #64, #79
feat(sanitizers): replace the ASAN variant with a UBSan one
feat(nix): build without the collector, so ASan runs the way Nix supp…
fix(nix): make the ASan build run, and stop pytest from hiding its re…
fix(nix): give the base environment room, and check the bound
test(nogc): keep an evaluator out of the pytest process without a col…
test(nogc): add a fork mode for the in-process tests, and record why …
test(nogc): fork every in-process test, and drop the second ASAN run
ci(nogc): run the no-collector suite on every commit