Skip to content

fix(daemon): only unlink the socket this daemon owns (prevents orphaned duplicate daemons) - #119

Draft
rgao-coreweave wants to merge 1 commit into
mainfrom
fix/daemon-orphaned-socket-unlink
Draft

fix(daemon): only unlink the socket this daemon owns (prevents orphaned duplicate daemons)#119
rgao-coreweave wants to merge 1 commit into
mainfrom
fix/daemon-orphaned-socket-unlink

Conversation

@rgao-coreweave

Copy link
Copy Markdown
Contributor

Summary

On restart, the old daemon's drain() closes its server early but unlinked the socket file late, after the (possibly slow) provider.shutdown() span flush. A daemon spawned during that window binds the path, and the old daemon's late unlink then deletes the new daemon's live socket ~a second later, orphaning it (listening on a dangling inode). The next hook then cold-starts yet another daemon: duplicate, flapping daemons.

Fix: record the inode of the socket this daemon bound and only release a socket file we still own (releaseOwnedSocket); drain() releases it up-front instead of after the flush; the process-exit handler is ownership-checked too.

Test plan

npm run check (build + 75 tests; 2 new pin the ownership check: releases its own socket, leaves a successor's rebind alone).

Reproduced while investigating: cold herds were already safe (0/32), but a restart racing a slow drain orphaned the successor 8/8; fixed after.

🤖 Generated with Claude Code

On `restart`, the old daemon's drain() closed its server early but unlinked the
socket file LATE — after the (possibly slow) provider.shutdown() flush. A daemon
spawned during that window bound the path, and the old daemon's late unlink then
deleted the NEW daemon's live socket ~a second later, orphaning it (listening on
a dangling inode) so the next hook cold-started another daemon: duplicate,
flapping daemons.

Record the inode of the bound socket and only release a socket file we still own
(releaseOwnedSocket); drain() releases it up-front instead of after the flush;
the process-exit handler is ownership-checked too. Cold herds were already safe;
this closes the restart / slow-drain path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant