← Back to Pull requests

Signal callbacks: Wait for running callbacks on deregistration #16836

Open
edolstra opened this pull request with 77 lines diff across 4 files
View on GitHub
edolstra edolstra commented on Nov 16, 2026 11:35 UTC
Author

<!--

IMPORTANT

Nix is a non-trivial project, so for your contribution to be successful,
it really is important to follow the contributing guidelines:

https://github.com/NixOS/nix/blob/master/CONTRIBUTING.md

Even if you've contributed to open source before, take a moment to read it,
so you understand the process and the expectations.

  • what information to include in commit messages

  • proper attribution

  • volunteering contributions effectively

  • AI/automation policy

  • how to get help and our review process.
  • PR stuck in review? We have two Nix team meetings per week online that are open for everyone in a jitsi conference:

  • https://calendar.google.com/calendar/u/0/embed?src=b9o52fobqjak8oq8lfkhg3t0qg@group.calendar.google.com
  • -->

    Motivation

    Fixes crashes where a signal callback runs after it has been deregistered and the objects it refers to have been destroyed. We saw this in crash reports from Determinate Nix, in nix-daemon (the interrupt callback in processConnection()) and in nix build (the ReceiveInterrupts callback). triggerSignalCallbacks() calls a copy of the callback after releasing the lock, and deregistration didn't wait for it to finish.

    Taken from https://github.com/DeterminateSystems/nix-src/pull/795.

    Implementation

    Add a mutex that is held while looking up and running a callback, and while deregistering one, so deregistration waits until no callback is running. Includes a unit test that fails without the fix.

    <!-- Invasive change: Discuss alternative designs or approaches you considered. -->

    <!-- Large change: Tell reviewers how to read the diff, e.g. which commits or files to look at first. -->

    ---

    Add :+1: to pull requests you find important.

    The Nix maintainer team uses a GitHub project board to schedule and track reviews.

    Diff: 77 lines (+76 / -1) across 4 files Reviewer: roberth Review duration: 25585m
    All Vouch review confidence checks passed
    Residual risk 0.09 = Change Risk (0.33) × (1 − Review Confidence (0.73)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.33 · 77 lines diff across 4 files
    0.33
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.61 · 1 substantive comment(s)
    0.61
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    72%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.261
    Real PR Conversation Timeline
    3 items
    roberth roberth commented on code on Nov 30, 2026 20:14 UTC
    Code Review
    src/libutil/include/nix/util/signals.hh:1
    @@ -77,13 +77,19 @@ enum class SignalType {
      * Register a function that gets called from the signal handler thread
      * (in a non-signal context) when the given signal type is received.
      *
    + * Destroying the returned object deregisters the callback, and waits
    + * until no other thread is running a signal callback. So the callback
    + * can safely refer to objects that are destroyed after deregistration,
    + * but callbacks must not wait for a thread that is deregistering a
    + * callback (e.g. by acquiring a lock that that thread holds).

     * callback (e.g. by acquiring a lock that that thread holds).
     * Furthermore, a callback must not invoke `triggerInterrupt()`, to avoid deadlock.
    

    roberth roberth approved these changes on Nov 30, 2026 20:15 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    edolstra edolstra
    Labels
    risk: low confidence: 72.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 33.5% (LOW) · Higher = larger blast radius
    33.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 72.9% · Lower = rushed or shallow review
    72.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 9.1% · Safe to merge
    9.1%
    Repository