fix(daemon): only unlink the socket this daemon owns (prevents orphaned duplicate daemons) - #119
Draft
rgao-coreweave wants to merge 1 commit into
Draft
fix(daemon): only unlink the socket this daemon owns (prevents orphaned duplicate daemons)#119rgao-coreweave wants to merge 1 commit into
rgao-coreweave wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On
restart, the old daemon'sdrain()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