Repository navigation
fix(server): let the Unix socket appear only once it listens with its mode - #16
Merged
Merged
Conversation
… mode net.Listen made the socket at its path, where it refused connections before its listen and accepted them, with the permissions of the umask, before its chmod. The socket is now made under a temporary name in the same directory, chmod-ed, and renamed to its path, which also replaces a stale socket in one step. The listener removes the socket at its path when it closes. The tests of the socket's mode and of the token failed under parallel load (9 runs of 10 with -race over ./internal/...); with this, 0 of 30. Co-Authored-By: Claude Opus 5.5 <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
listenUnixcreated the socket at its path withnet.Listenand ranchmodon it afterwards, so the socket was at the path for a moment before it was ready:-socket-mode.The second is a security hole, since
-socket-modedecides who may connect. The first made theTestUnixSocketandTestTokentests flaky under parallel load.Changes
.sock-<random>). It is then chmod-ed and renamed to its path, so it appears at the path only once it is listening with its mode.SetUnlinkOnClose(false).TestReplacesAStaleSocket: a stale socket is replaced, the new one accepts connections, and neither the socket nor the temporary file is left after shutdown.Verified
go test -race -count=1 ./internal/..., which runs the packages in parallel: the old code failed 9 runs of 10, the new code 0 of 30.scripts/lint.shpasses.🤖 Generated with Claude Code