Skip to content

Daemon: Ignore interrupts between accept() and child start#502

Merged
edolstra merged 1 commit into
mainfrom
eelcodolstra/nix-413
Jun 14, 2026
Merged

Daemon: Ignore interrupts between accept() and child start#502
edolstra merged 1 commit into
mainfrom
eelcodolstra/nix-413

Conversation

@edolstra

@edolstra edolstra commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Sending SIGINT to the nix-daemon parent process is supposed to stop the parent, not the children. So any connection that has been accept()ed should continue normally. However, there is a time window between the call to accept() and the fork() of the child where we could receive SIGINT, which would cause the child to throw an Interrupted exception. This shows up in the client as

error: cannot open connection to remote store 'daemon': read of 32768 bytes: Connection reset by peer

Solution: don't call checkInterrupts() after accept(), and clear the interrupt flag in the child process.

Context

Summary by CodeRabbit

  • Bug Fixes

    • Fixed interrupted state handling in daemon worker processes to prevent improper inheritance from parent context.
  • Chores

    • Removed redundant interrupt check in socket acceptance loop, streamlining interrupt handling flow.

Sending SIGINT to the nix-daemon parent process is supposed to stop
the parent, not the children. So any connection that has been
accept()ed should continue normally. However, there is a time window
between the call to accept() and the fork() of the child where we
could receive SIGINT, which would cause the child to throw an
"Interrupted" exception. This shows up in the client as

  error: cannot open connection to remote store 'daemon': read of 32768 bytes: Connection reset by peer

Solution: don't call checkInterrupts() after accept(), and clear the
interrupt flag in the child process.
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4af9cf80-19f3-4ca8-ab83-e2243477f45c

📥 Commits

Reviewing files that changed from the base of the PR and between d8c98d1 and 76518af.

📒 Files selected for processing (2)
  • src/libcmd/unix/unix-socket-server.cc
  • src/nix/unix/daemon.cc
💤 Files with no reviewable changes (1)
  • src/libcmd/unix/unix-socket-server.cc

📝 Walkthrough

Walkthrough

Two targeted interrupt-handling fixes in the Unix socket layer: a redundant checkInterrupt() call immediately before accept() is removed from the socket server's accept loop, and setInterrupted(false) is added at the start of each per-connection child worker in daemonLoop() to clear any inherited interrupted state.

Changes

Unix Socket Interrupt Handling

Layer / File(s) Summary
Remove redundant interrupt check; reset interrupted state in worker
src/libcmd/unix/unix-socket-server.cc, src/nix/unix/daemon.cc
The duplicate checkInterrupt() immediately before accept() is deleted from the accept loop. In daemonLoop(), the child worker lambda now calls setInterrupted(false) before handling the connection to prevent inheriting an interrupted state from the parent.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐇 Hop, hop, the interrupt's gone astray,
A leftover check swept cleanly away.
The child wakes fresh, no parent's alarm,
setInterrupted(false) — free from harm!
Accept the socket, the daemon rings clear,
No phantom signals to fill it with fear. 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: removing redundant interrupt checks between accept() and child process startup to prevent interrupts from affecting child processes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch eelcodolstra/nix-413

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

Copy link
Copy Markdown

@github-actions github-actions Bot temporarily deployed to pull request June 14, 2026 22:29 Inactive
@edolstra edolstra enabled auto-merge June 14, 2026 22:35
@edolstra edolstra added this pull request to the merge queue Jun 14, 2026
Merged via the queue into main with commit b00c7a0 Jun 14, 2026
30 checks passed
@edolstra edolstra deleted the eelcodolstra/nix-413 branch June 14, 2026 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants