gh-73458: Fix logging.config.listen() on a host without an IPv4 address#154491
Open
serhiy-storchaka wants to merge 2 commits into
Open
gh-73458: Fix logging.config.listen() on a host without an IPv4 address#154491serhiy-storchaka wants to merge 2 commits into
serhiy-storchaka wants to merge 2 commits into
Conversation
… address The server is created in a thread which set the "ready" event only after a successful start, so a failure to start left the caller waiting for that event forever. Set it also on failure. The receiver always used AF_INET, which fails if the host has no IPv4 address, for example if "localhost" is only aliased to ::1. Use the family of the first resolved address in such case. Also fixes pythongh-82076. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Like the other logging.config.listen() tests. It failed on WASI and Emscripten, which cannot start a thread. 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.
logging.config.listen()cannot be used on a host without an IPv4 address, and any failure to start the server leaves the caller waiting forever.The server is created in a thread which set the
readyevent only after a successful start, so if the receiver could not be constructed, the thread died andt.ready.wait()blocked forever. This is the hang reported in gh-73458 and gh-82076. It happens for any failure to start, not only on IPv6 hosts: an invalid or already used port hangs the caller too.ConfigSocketReceiveralso inheritedaddress_family = AF_INETfromThreadingTCPServerwhile binding the namelocalhost, so the bind fails iflocalhosthas no IPv4 address. The family is now taken from the resolved address, but only when there is no IPv4 address, so dual-stack hosts keep binding IPv4 as before. Resolution errors are left to the server, so an invalid port still reports the same exception as before.Verified by patching
socket.getaddrinfo()so thatlocalhostresolves only to::1: before the change the client getsConnectionRefusedError, after it the connection is made overAF_INET6and the configuration is delivered. With ports-1,65536,99999,'http','nosuchservice',Noneand1.5the raised exception types are unchanged; only the hang is gone.The test no longer forces
AF_INETwhen connecting, and the waits forreadynow have a timeout, so a regression fails instead of hanging.🤖 Generated with Claude Code