Skip to content

feat/startup: add domain socket for daemon launch to funnel information - #3015

Merged
sylvestre merged 14 commits into
mainfrom
bs-dist-daemon-fd-fun
Nov 27, 2026
Merged

sylvestre merged 14 commits into
mainfrom
bs-dist-daemon-fd-fun

Conversation

@drahnr

@drahnr drahnr commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Currently early daemon issues are swallowed, since we daemonize rather early on.

Once we land we #2241 it's getting more pressing due to the non-fork-compatibility of tokio (see process global state which is assume to remain alive without access from outside
https://github.com/tokio-rs/tokio/blob/tokio-1.54.1/tokio/src/signal/registry.rs#L144-L151 and the issue tokio-rs/tokio#4301). We would be able to pass file descriptors to retain into daemonize, but we don't have access to those, neither directly or indirectly. Writing pre and post runtime init is hacky and brittle, so I'd rather not.

I pulled this PR out from as a prequel to #2241 to a) ensure not introducing any error conditions and b) retaining a more manageable changeset size.

Assuming the tokio runtime would already be present as per #2241

sccache-dist scheduler --config ...
                  |
                  v
       Initialize client authentication
                  |
          JWT validation enabled?
                  |
                  v
       Create temporary Tokio runtime
                  |
                  v
              Fetch JWKs
                  |
                  v
       Drop temporary Tokio runtime
       (global signal FDs remain open)
                  |
                  v
              daemonize()
                  |
          +-------+------------------------+
          |                                |
          v                                v
   Original command                     Daemon
     exits with 0                          |
                                           v
                                Close inherited FDs
                                (also closes Tokio's
                                 global signal FDs)
                                           |
                                           v
                                Create service runtime
                                           |
                                           X
                                "Bad file descriptor"
                                           |
                                           v
                                Error goes to /dev/null

   User sees success, but the scheduler failed to start.

becomes

Failure paths

Daemon initialization error
          |
          +---- Error + cause chain ----> Original command
                                                  |
                                                  v
                                           Print error
                                           Exit nonzero


Original command disappears / startup times out
          |
          v
Daemon-side watchdog terminates failed startup
(even if runtime teardown is stuck)

The background startup timeout is 60 seconds (= EOF before readiness | invalid response | missing ack(

Foreground mode

SCCACHE_NO_DAEMON=1 sccache-dist scheduler --config ...
                  |
                  v
       Existing daemon setup / FD cleanup
                  |
                  v
       Initialize authentication and Tokio
                  |
                  v
              Bind and serve

Foreground mode does not fork or require the background startup handshake.

@codecov-commenter

codecov-commenter commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.29126% with 70 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.47%. Comparing base (0e8f184) to head (ee25b66).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/bin/sccache-dist/main.rs 42.85% 28 Missing ⚠️
tests/sccache_dist.rs 93.18% 24 Missing ⚠️
src/bin/sccache-dist/startup.rs 95.73% 13 Missing ⚠️
src/dist/http.rs 25.00% 3 Missing ⚠️
src/util.rs 81.81% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3015      +/-   ##
==========================================
+ Coverage   79.99%   80.47%   +0.48%     
==========================================
  Files          76       78       +2     
  Lines       47373    48280     +907     
==========================================
+ Hits        37894    38855     +961     
+ Misses       9479     9425      -54     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@drahnr drahnr changed the title fix: tokio global state sockets cleanup fix: only spawn tokio _after_ daemonize, tokio global state, intro start socket Nov 12, 2026
Keep runtime and authentication initialization in the daemon, and report readiness or startup errors to the original process.
@drahnr
drahnr force-pushed the bs-dist-daemon-fd-fun branch from ae101af to 3b657d6 Compare November 12, 2026 16:13
Comment thread docs/DistributedQuickstart.md Resolved
@drahnr drahnr changed the title fix: only spawn tokio _after_ daemonize, tokio global state, intro start socket feat/startup: add domain socket for daemon launch to funnel information Nov 24, 2026
@drahnr
drahnr marked this pull request as ready for review November 24, 2026 16:37
Copilot AI balanced review requested due to automatic review settings November 24, 2026 16:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

There are no active review issues with the daemon startup handshake changes.

No open issues 🎉

What changed in this PR

This PR adds a Unix-domain socket handshake between the scheduler daemon and its launcher so startup failures reach the invoking command. It prepares for the HTTP migration in #2241 by moving authentication initialization after daemonization.

Changes:

  • Wait for daemon readiness and propagate startup errors, with a timeout and watchdog.
  • Preserve foreground operation while separating daemonization from cleanup.
  • Add startup, authentication, and process-cleanup tests, and document launcher behavior.
File Description
tests/​sccache_dist.rs Tests error reporting, readiness, and closed standard descriptors.
tests/​dist_daemon.rs Tests detached initialization, JWT authentication, and process cleanup.
src/​util.rs Separates parent-aware daemonization from post-fork cleanup.
src/​dist/​http.rs Adds a readiness callback after scheduler listener setup.
src/​bin/​sccache-dist/​startup.rs Implements startup messaging, acknowledgment, timeout, and watchdog.
src/​bin/​sccache-dist/​main.rs Routes scheduler initialization through the startup handshake.
docs/​DistributedQuickstart.md Documents startup waiting and failure reporting.

Review effort: Balanced

@drahnr drahnr self-assigned this Nov 24, 2026
Comment thread tests/dist_daemon.rs Resolved
Comment thread tests/sccache_dist.rs Resolved
Comment thread tests/sccache_dist.rs Resolved
Comment thread tests/sccache_dist.rs Resolved
Comment thread src/bin/sccache-dist/startup.rs Resolved
Keep startup failures, readiness, JWT authentication, descriptor cleanup, and detachment checks in one integration target. Exercise launcher loss during blocked JWKS retrieval and serialize descendant cleanup.
Reject malformed, truncated, oversized, and empty-error startup responses and incorrect readiness confirmations. Synchronize watchdog setup with blocking runtime work and bound child-process waits.
drahnr added a commit that referenced this pull request Nov 26, 2026
@sylvestre
sylvestre merged commit 01bf270 into main Nov 27, 2026
101 checks passed
@sylvestre

Copy link
Copy Markdown
Collaborator

Thanks for your PR

@drahnr
drahnr deleted the bs-dist-daemon-fd-fun branch November 27, 2026 21:26
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.

4 participants