Repository navigation
Skip filesystem checks for abstract namespace unix sockets - #3718
Merged
benoitc merged 1 commit intoAug 31, 2026
Merged
Conversation
Linux supports abstract namespace unix sockets, whose address starts with a null byte and has no presence on the filesystem. Binding gunicorn to one (e.g. bind = "unix:\0my-socket") currently crashes before the server even starts: ValueError: embedded null byte This happens because UnixSocket.__init__ always calls os.stat() on the address to check for and remove a stale socket file left over from a previous run. os.stat() rejects paths containing an embedded null byte outright, so it never gets a chance to return ENOENT the way a normal missing path would. The same problem exists in bind(), which unconditionally chowns the socket path afterward. That call would fail the same way once the os.stat() call above is no longer in the way. Since abstract sockets don't exist on the filesystem, there's nothing to stat, remove, or chown for them, so both operations are skipped when the address starts with a null byte.
Owner
|
Thanks @afonsojanu, merged. |
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.
Fixes #2699.
Linux supports abstract namespace unix sockets, whose address starts with a null byte and has no presence on the filesystem. Binding gunicorn to one currently crashes before the server starts:
UnixSocket.__init__always callsos.stat()on the address to check for and remove a stale socket file from a previous run.os.stat()rejects any path with an embedded null byte outright, so it never has a chance to returnENOENTthe way a genuinely missing path would, and theValueErrorpropagates straight out of the constructor.bind()has the same problem a step later: it unconditionally chowns the socket path, which would fail the same way once the stat call above stops being in the way.Since abstract sockets don't exist on the filesystem, there's nothing to stat, remove, or chown for them, so both operations are skipped when the address starts with a null byte.
Added tests covering:
os.stat()bind()skipschown()for an abstract-namespace addressRan the full test suite plus pylint and pycodestyle on the touched files, all clean.