8000 nix: the shipped collector aborts on a thread-exit race, because the patch for it reached only sanitized builds · Issue #101 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

nix: the shipped collector aborts on a thread-exit race, because the patch for it reached only sanitized builds #101

Closed

Description

@Lillecarl

What happens

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:

direnv exec . timeout 300 pytest tests -m soak --soak-seed=$SEED -q --capture=no --nix-test-backends local,daemon
collector runs SIGABRT SIGSEGV
unpatched (what shipped) 15 6 4
patched 15 0 1

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.

Not the same as #98

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.

Activity

  1. Lillecarl commented on Aug 4, 2026

    @Lillecarl
    ContributorAuthor

    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.

  2. Lillecarl commented on Aug 4, 2026

    @Lillecarl
    ContributorAuthor

    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.

  3. added
    source: nanopynix
    on Oct 19, 2026
  4. 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