8000 ci: the runaway-recursion tests overflow the stack under ASAN on Nix 2.34 and later · Issue #100 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

ci: the runaway-recursion tests overflow the stack under ASAN on Nix 2.34 and later #100

Closed

Description

@Lillecarl

Three tests fail in test-asan-nix_2_34, test-asan-nix_2_35 and
test-asan-git, and they are the only failures in those jobs:

FAILED tests/nanopynix/test_scalar_accessor_semantics.py::test_inproc_reports_runaway_recursion_at_nixs_default_depth[local] - :-1: running the test CRASHED with signal 0
FAILED tests/nanopynix/test_engine_parity_semantics.py::test_engines_agree_on_failure[local-runaway_recursion] - :-1: running the test CRASHED with signal 0
FAILED tests/nanopynix/test_scalar_accessor_semantics.py::test_rpc_reports_runaway_recursion_at_nixs_default_depth[local] - nanopynix.exceptions.WorkerDiedError: Connection lost
= 3 failed, 1694 passed, 18 skipped, 1 xfailed, 26 warnings in 1153.59s

ASAN says what it is:

==22022==ERROR: AddressSanitizer: stack-overflow on address 0x7b4fb70199e8 (pc 0x7b4fc2aba290 bp 0x7b4fb701b2c0 sp 0x7b4fb7019910 T3)

Why the tests exist, and why ASAN loses

test_scalar_accessor_semantics.py:394-404 states the contract: at Nix's
default max-call-depth of 10000, the recursion needs about 27 MB of C stack.
The evaluator thread therefore gets the 60 MiB that nix::initNix() asks
for, so Nix's own counter wins the race against the C stack. The comment 8000
also says what a regression looks like, and it is what happened here: the
test does not fail, the process dies.

ASAN gives each frame redzones and stops the compiler from reusing stack
slots, so the same 10000 frames no longer fit in 60 MiB. The guard is
calibrated for a build with no instrumentation.

Proven pre-existing, and version-dependent

Run 30907694264
is develop at 689ec37c, with no branch work on it. It fails exactly
test-asan-nix_2_34, test-asan-nix_2_35 and test-asan-git, and nothing
else: {"failure": 3, "skipped": 2, "success": 22}.

test-asan-nix_2_31 passes both tests in the same matrix:

tests/nanopynix/test_scalar_accessor_semantics.py::test_inproc_reports_runaway_recursion_at_nixs_default_depth[local] PASSED
tests/nanopynix/test_scalar_accessor_semantics.py::test_rpc_reports_runaway_recursion_at_nixs_default_depth[local] PASSED

So the cost of an eval frame grew between 2.31 and 2.34, and 60 MiB stopped
being enough under ASAN somewhere in that step. Find the change before you
pick a number.

Two ways to correct it, and what each costs

  1. Give the evaluator thread more stack under ASAN. This keeps the test
    doing its job in the ASAN job as well. It needs a measurement of the real
    frame cost under ASAN, and a rule for where the number comes from, rather
    than a constant that the next Nix version invalidates again.
  2. Skip the three tests under ASAN. This is cheap and it is honest, and
    it removes ASAN coverage of the one path that is about the stack.

Option 1 is the better answer if the number can be derived. Do not weaken
the assertion in either case.

The marker cannot express this yet

nix_known_issue(exclude=..., sanitizer=...) is the marker for a bounded
defect, and sanitizer="asan" is already accepted. _version_in_exclusions
(tests/support/nix_runtime.py:197) matches a version prefix only, so
there is no way to write "2.34 and later". A skip would have to list every
version, and the list would be wrong the day a new one arrives.

Acceptance criteria

  • test-asan-nix_2_34, test-asan-nix_2_35 and test-asan-git finish with
    no failure.
  • The reason the tests pass is written down: either the stack number and
    where it comes from, or the skip and the marker that carries it.
  • If the marker gains a version range, tests/meta/ gains the self-check
    for it.

Activity

  1. Lillecarl commented on Aug 4, 2026

    @Lillecarl
    ContributorAuthor

    Option 1 is not available. The stack is not what runs out.

    I built the ASAN runner for 2.34 and reproduced the failure locally in 3.2
    seconds, then swept the evaluator stack size. More stack does not fix it.
    It moves the failure.

    stack result
    60 MiB fails: ASAN SEGV on unknown address 0x03e8001e3b49, a WRITE
    120 MiB fails: ASAN CHECK failed: asan_thread.cpp:369
    180 MiB the same
    240 MiB the same
    320 MiB the same
    400 MiB the same

    The change of failure between 60 and 120 MiB is what proves the knob took
    effect.

    What happens at and above 120 MiB

    Nix's counter does win the race at that point. It throws
    max-call-depth, and the C++ exception unwinds out of 10000 frames. The
    unwind calls __asan_handle_no_return, and ASAN then fails a CHECK inside
    its own thread bookkeeping:

    WARNING: ASan is ignoring requested __asan_handle_no_return: stack type: default
      top: 0x6ea92a6f5ec0; bottom 0x6ea925525000; size: 0x51d0ec0 (85790400)
    False positive error reports may follow
    AddressSanitizer: CHECK failed: asan_thread.cpp:369 "((ptr[0] == kCurrentStackFrameMagic)) != (0)"
        nixidae/nixidae#31 __asan::AsanThread::GetStackFrameAccessByAddr(...)
        nixidae/nixidae#32 __asan::GetStackAddressInformation(...)
        nixidae/nixidae#36 sigaltstack.part.0
        nixidae/nixidae#37 __asan::PlatformUnpoisonStacks()
        nixidae/nixidae#38 __asan_handle_no_return
       nixidae/nanopynix#10 std::default_delete<nix::DebugTraceStacker>::operator()(...)
       nixidae/nanopynix#12 nix::ExprCall::eval(...) ../eval.cc:1778
    

    Every frame from #0 to #38 is inside libasan.so. Nothing Nix or nanopynix
    does decides the outcome.

    Note the size ASAN reports for the thread stack: 85790400 bytes, or about
    82 MiB, at both 120 and 240 MiB. ASAN's record of the evaluator thread's
    bounds does not follow threading.stack_size(), so the recursion runs off
    the stack ASAN believes in, and its own machinery then walks memory that is
    not a frame.

    detect_stack_use_after_return=0 does not help either. Measured, by
    patching a copy of the runner, since the runner exports ASAN_OPTIONS
    itself:

    60 MiB, no-SUAR: 1 failed
    120 MiB, no-SUAR: 1 failed
    240 MiB, no-SUAR: 1 failed
    

    with the same CHECK failure.

    So the three tests are skipped under ASAN

    nix_known_issue(sanitizer="asan", reason=...) now marks the two in
    test_scalar_accessor_semantics.py and the runaway_recursion case of the
    parity matrix. The reason each carries names this issue.

    This is not "ASAN is slow" or "ASAN is noisy". The premise of the tests is
    that Nix's counter can win the race against the C stack. Under ASAN the
    counter wins and the unwind fails, so there is no stack size at which the
    tests can pass, and no assertion in them that could be made true.

    The marker gained the bound it needed, and lost a defect on the way

    nix_known_issue required exclude, so a defect of the instrumentation had
    no way to say so. It now takes exclude, or sanitizer, or both, and
    refuses a marker that gives neither -- a marker with no bound skips
    everywhere and never comes back.

    While adding the self-check for that I found _version_in_exclusions
    inverted.
    It compared padded() on both sides, and padded only ever
    adds parts. So "2.34" meant the two-part version 2.34 and never matched
    a released 2.34.8 -- while a Nix built from git reports 2.35pre2026...,
    which parses to exactly (2, 35) and did match "2.35".

    Every exclusion in the tree is written with two parts, so this was not
    theoretical. test_inproc_mixed_evaluation_build_and_store_workloads
    carried:

    @pytest.mark.nix_known_issue(
        exclude=("2.34", "2.35"),
        sanitizer="tsan",
        reason="nix::LocalStore crashes under TSAN in released Nix; fixed on Nix master",
    )

    and did the opposite of what it says. Measured in runs 30930842932 and
    30934106841:

    job outcome
    test-tsan-nix_2_34 PASSED -- the marker never fired
    test-tsan-nix_2_35 PASSED -- the marker never fired
    test-tsan-git SKIPPED -- the build it was written to spare

    The matcher now compares at the precision of the exclusion, so "2.34" means
    the 2.34 series. The marker itself is removed rather than corrected: a
    corrected one would skip all three builds, and the runs above say the test
    passes under TSAN on both released versions. tests/meta/test_known_issue_marker.py
    pins all of this.

  2. Lillecarl commented on Aug 4, 2026

    @Lillecarl
    ContributorAuthor

    The three skips are in, and the ASAN matrix is green

    Run 30940324091, on ci-develop, with nix_known_issue(sanitizer="asan") on
    the two tests in test_scalar_accessor_semantics.py and on the
    runaway_recursion case of the parity matrix:

    job before after
    test-asan-nix_2_31 success success
    test-asan-nix_2_34 failure success
    test-asan-nix_2_35 failure success
    test-asan-git failure success

    The three failures were the same three in run 30934106841 and in run
    30907694264 on develop, so this is the first run in which every ASAN job
    passes.

    The issue stays open. The skips record a defect of the instrumentation, and
    they come back the day a libasan can unwind out of max-call-depth. The
    measurement that says no stack size helps is in the comment above.

  3. Lillecarl commented on Aug 5, 2026

    @Lillecarl
    ContributorAuthor

    All acceptance criteria hold. Measured on run
    31055578130,
    the full matrix on develop at 09fa83eb: 27 jobs green, 0 failures.

    1. "test-asan-nix_2_34, test-asan-nix_2_35 and test-asan-git finish
    with no failure."
    All three, and test-asan-nix_2_31 as well. No
    stack-overflow report in any of them.

    The last ASAN failure was a different defect -- the host /bin/sh of
    test_store_dump_db.py under the sanitizer LD_PRELOAD -- and it has its own
    issue, #121, now closed. That is why these jobs stayed red after the skip
    landed.

    2. "The reason the tests pass is written down." Option 2, and the reason
    option 1 was rejected is written down with it.
    tests/nanopynix/test_scalar_accessor_semantics.py:405-412 carries the sweep:

    from 60 to 400 MiB the failure moves and never goes away. Below about
    120 MiB the instrumented frames exhaust the stack before the counter fires.
    At or above it the counter does fire, and then the max-call-depth
    exception unwinds through __asan_handle_no_return, where ASAN reports
    "ASan is ignoring requested __asan_handle_no_return" and fails its own
    CHECK in asan_thread.cpp:369.

    So no stack number answers this. The failure is inside libasan, and neither
    Nix nor nanopynix decides it. _ASAN_CANNOT_UNWIND is the marker that
    carries the skip, and the three tests report it:

    SKIPPED tests/nanopynix/test_scalar_accessor_semantics.py:421: ASAN fails a CHECK of its own while unwinding max-call-depth (#71); under asan
    SKIPPED tests/nanopynix/test_scalar_accessor_semantics.py:432: ASAN fails a CHECK of its own while unwinding max-call-depth (#71); under asan
    SKIPPED tests/nanopynix/test_engine_parity_semantics.py:359: ASAN fails a CHECK of its own while unwinding max-call-depth (#71); under asan
    

    3. "If the marker gains a version range, tests/meta/ gains the self-check
    for it."
    Not applicable, and deliberately so. The marker did not gain a
    range. sanitizer="asan" needs no version list, which is what the issue said
    a version list would get wrong the day a new Nix arrives. abc3da693f0f
    separately corrected _version_in_exclusions to match at the precision of
    the exclusion, but that is prefix matching and not a range.

    What it costs

    test-asan-nix_2_31 used to pass these two tests, and it skips them now. The
    marker is version-blind, so ASAN coverage of the one path that is about the
    stack is gone on every version rather than on the versions that need it. That
    is the price the issue named for option 2, and it is paid knowingly.

    Closing.

  4. added
    source: nanopynix
    on Oct 19, 2026
  5. added theissue type on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    source: nanopynix

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0