8000 tsan: Boehm's stop-the-world aborts the soak, because TSAN intercepts the signals it suspends threads with · Issue #98 · nixidae/nixidae · GitHub
[go: up one dir, main page]

Skip to content

tsan: Boehm's stop-the-world aborts the soak, because TSAN intercepts the signals it suspends threads with #98

Closed

Description

@Lillecarl

What happens

The TSAN concurrency soak aborts, at a rate near one run in four. The process
dies with SIGABRT, and no data race is reported.

Signals delivery fails constantly at GC nixidae/nixidae#30
Signals delivery fails constantly
Fatal Python error: Aborted

  libc.so.6, at abort
  libtsan.so, at __interceptor_abort
  libgc.so.1, at GC_generic_malloc_many
  libnixexpr.so.2.34.8, at nix::EvalState::allocValue

Boehm suspends every other thread with a signal before it collects. TSAN
intercepts signal delivery. When Boehm cannot stop the world it gives up and
calls abort, and TSAN's own abort interceptor is the frame above it.

nix::EvalState::allocValue is the allocation that triggers the collection,
so the soak's evaluator work is what reaches it.

Measurements

Every run below is seed 2, local,daemon, on the same machine.

build ceiling runs aborts
this branch vomit (the default) 7 2
this branch error 8 2
before the verbosity fix vomit 8 0

The ceiling does not matter. NANOPYNIX_LOG_CEILING=error restores the
gate that Nix had before #92 pinned the global, so a debug() site drops its
message without formatting it. That removes the extra allocation and the
extra time per log site, which was the one mechanism by which #92 could reach
a timing-sensitive failure. The abort rate does not move.

The last row is not evidence of a difference. At a rate of 4 in 15, the
probability of 0 aborts in 8 runs is 0.73^8, near 0.08. The two builds also
have different roster membership, and this failure is sensitive to allocation
pressure. So the row neither shows that #92 causes the abort nor shows that
it does not.

What is clear: the soak is the workload that reaches this. The TSAN job on
develop has no soak, and it passes.

Why this is upstream, and what is left to decide

Boehm and TSAN disagree about who owns signal delivery. Neither Nix nor
nanopynix chooses that. The options that this repository does control:

  1. Give the soak job a ret 8000 ry budget. The failure is not a finding, so a
    run that aborts says nothing about the code. A retry keeps the job honest
    about races while it tolerates a collector that cannot stop the world.
  2. Lower the allocation pressure of the soak. Fewer lanes, or fewer
    evaluator-heavy tests in one lane, means fewer collections.
  3. Ask Boehm to use a different signal. GC_set_suspend_signal and
    GC_set_thr_restart_signal exist. Whether a signal outside TSAN's
    interception set works is untested.

Option 1 is the smallest, and it does not hide a race: TSAN reports a race
before the process reaches a collection, and a race already fails the job on
its own.

Acceptance criteria

  • The soak job does not go red on an abort that reports no race.
  • A run that does report a race still fails the job.
  • The log says plainly that an abort happened, and how many attempts ran, so
    a reader can see the rate rather than guess it.

Refs #92

Activity

  1. Lillecarl commented on Aug 4, 2026

    @Lillecarl
    ContributorAuthor

    Root cause found, and Boehm already carries the correction

    Boehm knows about this failure, and it has a branch for it.
    include/private/gc_priv.h:

    # ifdef THREAD_SANITIZER
        /* Unfortunately, use of an asynchronous signal to suspend threads
           leads to the situation when the signal is not delivered (is
           stored to pending_signals in TSan runtime actually) while the
           destination thread is blocked in pthread_mutex_lock.  Thus, we
           use some synchronous one instead ... */
    #   define SIG_SUSPEND SIGSYS
    

    That is the abort, described by the people who wrote the collector. Without
    the macro the suspend signal is SIGPWR, which is asynchronous, and the
    TSAN runtime holds it. Boehm then gives up and calls abort.

    The macro does not define itself in this build. gcconfig.h sets it
    from __has_feature(thread_sanitizer), and the branch for a compiler with
    no __has_feature reads __SANITIZE_ADDRESS__ only -- there is no
    __SANITIZE_THREAD__ beside it. This build uses GCC 15.3.0. So
    nix/sanitizer.nix instrumented boehmgc without telling boehmgc what
    instruments it, and the signal stayed the wrong one.

    sanitizeBoehmGC now passes -DTHREAD_SANITIZER, for the TSAN variant
    alone. The UBSAN variant also builds a collector, and SIGSYS there would
    change what that job exercises for no reason.

    This closes the question the issue asked

    The issue text said: "Ask Boehm to use a different signal ... Whether a
    signal outside TSAN's interception set works is untested." It is not
    untested by Boehm, and SIGSYS is the answer they shipped.

    What the earlier answers were, and why they are not enough

    • GC_INITIAL_HEAP_SIZE=2 GiB. A collection that never happens cannot
      fail to stop the world, so a bigger initial heap lowers the rate. It took
      three targeted TSAN jobs green, and then test-tsan-nix_2_34 aborted
      again on the next full matrix run. It lowers a probability, and it
      corrects nothing. Removed.
    • The retry budget in the soak step. This stays. It tolerates exactly
      one signature -- status 134 together with Signals delivery fails -- and
      a race or any other non-zero status still fails the job. Keep it as the
      guard that says whether the signal fix holds, rather than deleting the
      evidence.
  2. Lillecarl commented on Aug 4, 2026

    @Lillecarl
    ContributorAuthor

    Correction: the comment above is wrong, and the build already does this

    I wrote that gcconfig.h cannot detect ThreadSanitizer on GCC, and that
    -DTHREAD_SANITIZER was therefore the missing correction. Both claims are
    false.
    GCC 15 supports __has_feature, and it reports thread_sanitizer
    under -fsanitize=thread:

    #if defined(__has_feature)
    #  if __has_feature(thread_sanitizer)
    #    error "HAS_FEATURE_TSAN_TRUE"
    ...
    $ gcc -fsanitize=thread -c probe.c
    probe.c:3:6: error: #error "HAS_FEATURE_TSAN_TRUE"
    $ gcc --version
    gcc (GCC) 15.3.0

    gcconfig.h:3325-3341 guards the whole block on defined(__has_feature)
    alone, so the macro is set. Against the real headers of the boehmgc that
    this build uses:

    #include "gc.h"
    #include "private/gcconfig.h"
    #ifdef THREAD_SANITIZER
    # error "THREAD_SANITIZER_IS_DEFINED"
    #endif
    
    $ gcc -fsanitize=thread -I .../boehmgc-source/include -c sigprobe2.c
    sigprobe2.c:6:3: error: #error "THREAD_SANITIZER_IS_DEFINED"

    And the selection block of gc_priv.h:3033-3048, replicated against those
    same headers, takes the SIGSYS branch:

    sigprobe3.c:10:5: error: #error "SIG_SUSPEND would be SIGSYS"
    

    So the collector this job links already suspends with SIGSYS, and it
    aborts anyway.
    The -DTHREAD_SANITIZER flag I added changes no
    preprocessor state, and it is withdrawn. The measurement I quoted for it
    never ran: I cancelled the job once the probes above answered the question.

    GC_INITIAL_HEAP_SIZE=2147483648 is back in the soak step, described as
    what it is -- a way to collect less often, which lowers the rate and
    corrects nothing.

    What this rules out, and where to look next

    SIGPWR versus SIGSYS is not the cause. The abort comes from
    resend_lost_signals in pthread_stop_world.c:490: it resends the suspend
    signal every 100 ms, and gives up after 150 tries with no progress. Fifteen
    seconds of a thread that never acknowledges a synchronous signal is not a
    lost signal. It is a thread that does not reach the handler.

    Two things to check before anything else:

    • Which thread does not acknowledge. GC_COND_LOG_PRINTF already prints
      Resent %d signals after timeout, retry: %d on each pass, so
      GC_PRINT_STATS=1 names how many threads are outstanding for fifteen
      seconds before the abort.
    • Whether that thread is inside the TSan runtime. The comment in
      gc_priv.h blames pthread_mutex_lock, and GC_usleep
      (pthread_stop_world.c:41) already spins with sched_yield under
      THREAD_SANITIZER to work around "a rare hang in usleep() trying to
      acquire TSan Lock". A thread that holds a TSan internal lock and cannot
      run a signal handler fits every symptom, and no signal number changes it.

    GC_RETRY_SIGNALS=0 is not a workaround. It removes the retry loop, so the
    abort becomes an unbounded wait in suspend_restart_barrier.

  3. Lillecarl commented on Aug 4, 2026

    @Lillecarl
    ContributorAuthor

    This abort, #82 and #101 are one condition at one call site

    Boehm's stop-the-world signal path has three ways to end when the thread it
    wants to suspend is not there, and this repository has now seen all three:

    issue outcome where
    #101 pthread_kill failed at suspend: errcode= 22 GC_suspend_all, raise_signal returns EINVAL
    #82 SIGSEGV inside pthread_kill GC_suspend_all, glibc reads a thread descriptor that is gone
    this one Signals delivery fails constantly at GC #N resend_lost_signals, pthread_stop_world.c:491, after 150 retries

    The third row is new evidence and it is not from TSAN. The 48-second
    reproducer on #82 was run against a collector built with
    --enable-gc-assertions, four times. Three ended in SIGSEGV and the fourth
    aborted, and addr2line on the frames of that abort gives:

    resend_lost_signals   pthread_stop_world.c:491
    GC_stop_world         pthread_stop_world.c:1115
    GC_stopped_mark       alloc.c:844
    GC_try_to_collect_inner   alloc.c:624
    GC_try_to_collect_general alloc.c:1303
    GC_gcollect
    

    So the same selection, on the same machine, with no sanitizer, produces this
    issue's abort and #82's fault interchangeably. A thread that never answers is
    a thread that resends 150 times and gives up; a thread whose descriptor has
    been reclaimed is a fault in the pthread_kill itself. Which one lands is
    timing.

    What that changes

    TSAN is not required, and TSAN is not the cause. This issue's measurements
    were all under TSAN, and the conclusion drawn was that TSAN's signal
    interception was the mechanism. The plain dev shell reaches the same abort.

    The remaining question is the one #82 now carries: which thread is in
    GC_threads that should not be.
    A registration audit over one crashing run
    pairs 17 enters with 16 exits plus the live one, and never reports
    GC_DUPLICATE, so nanopynix's own hooks are balanced.

    The assertion build is worth keeping in mind for whoever picks this up: it
    reproduces at the same rate as a plain build, so GC_ASSERTIONS fires on
    nothing here. Boehm's own invariants hold right up to the signal.

  4. 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.

  5. Lillecarl commented on Aug 5, 2026

    @Lillecarl
    ContributorAuthor

    All three acceptance criteria are met, and the mechanism that meets them is
    option 1. ci/workflows/lib.nix:477-490 retries an attempt that exits 134
    with Signals delivery fails, counts it, and fails the job only when the
    count passes ABORT_BUDGET:

    • "The soak job does not go red on an abort that reports no race."
      if [ "$aborts" -gt "$ABORT_BUDGET" ], and nothing else fails on 134.
    • "A run that does report a race still fails the job." The
      ThreadSanitizer: data race grep runs first, sets race_found=1, and
      breaks out to exit 1. It reads $RUNLOG and not the whole log, so an
      earlier attempt cannot answer for this one.
    • "The log says plainly that an abort happened, and how many attempts ran."
      === TSAN soak summary: N tolerated collector abort(s) of a budget of 5 ===,
      plus the Boehm resend log of each aborted attempt.

    The budget is no longer being spent

    Every test-tsan-* job since 99f74d82 ("register the thread that builds an
    evaluator with Boehm") reports zero aborts. Eighteen jobs, six runs,
    three Nix versions, and each job runs five seeds against the local and the
    daemon backends:

    run 2.34 2.35 git
    31027999591 0 0 0
    31031754724 0 0 0
    31034737291 0 0 0
    31043196896 0 0 0
    31047537102 0 0 0
    31051301905 0 0 0

    The four jobs that are red in that table failed on the gmtime race (#90) and
    on the soak verbosity defect (#91). Neither reached a collector abort.

    That rate is what #101 predicted. The abort was not the upstream disagreement
    between Boehm and TSAN that this issue opens with. It was one bug with #82 and
    #101: GC_INIT ran on a store pool thread that later exited, so the collector
    signalled a pthread_t that glibc had handed on.

    Closing. The retry budget stays, and #122 asks whether it should now be zero.

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