Skip to content

gh-59060: Support IPv6 in logging.handlers.DatagramHandler#154496

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:fix-datagramhandler-ipv6
Open

gh-59060: Support IPv6 in logging.handlers.DatagramHandler#154496
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:fix-datagramhandler-ipv6

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

DatagramHandler always created an IPv4 socket, so it could not send to an IPv6 address.

Sending to ::1 failed with gaierror(-9, 'Address family for hostname not supported'), and since emit() passes such errors to handleError(), the log record was silently lost. This is why the problem went unnoticed for so long.

The socket family is now taken from the resolved address, but only if the host has no IPv4 address, so on dual-stack hosts an IPv4 socket is still created as before. Resolution errors are left to sendto().

SocketHandler (which uses socket.create_connection()) and SysLogHandler (which iterates over socket.getaddrinfo() results) already support IPv6, so DatagramHandler was the only remaining gap.

The new IPv6DatagramHandlerTest mirrors the existing IPv6SysLogHandlerTest; it fails without the fix and passes with it. The waits in DatagramHandlerTest got a timeout, because otherwise a failure hangs the test instead of reporting it.

🤖 Generated with Claude Code

It always created an IPv4 socket, so sending to an IPv6 address failed and
the log record was silently lost.  Create a socket of the family of the
resolved address if the host has no IPv4 address.

Also add a timeout to the waits in DatagramHandlerTest.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33711175 | 📁 Comparing 130ff0f against main (3479e45)

  🔍 Preview build  

3 files changed
± library/logging.handlers.html
± whatsnew/3.16.html
± whatsnew/changelog.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant