Repository navigation
Close the DNS resolver, also when a lookup is cut short - #1592
Merged
Merged
Conversation
A new DNSResolver was created for every lookup and never closed. When the request timeout cut a lookup short, the query stayed pending in pycares, and the Python process could crash with a segmentation fault once the event loop shut down.
4 of 11 tasks
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.
Breaking change
None.
Proposed change
Found while testing the debug logging. The client created a new
DNSResolverfor every server lookup and never closed it. Since #1569, the request timeout also covers that lookup, so a slow lookup gets cut short. The query then stays pending inside pycares, and once the event loop shuts down, the Python process can crash with a segmentation fault:(exit code 139). For Home Assistant, that means a crash on shutdown or restart if a Radio Browser lookup was in flight.
The resolver is now used as an async context manager, which aiodns provides for exactly this: it cancels pending queries and releases the channel, also when the lookup is cancelled.
Measured with a
RadioBrowserwhose lookups are cut short by a tiny timeout, 20 runs each: 18 of 20 crashed before this change, 0 of 20 after. The new tests check that the resolver is closed after a normal lookup, and after every lookup the timeout cuts short.Type of change
Additional information
Checklist
poetry run pytestpasses locally. A pull request cannot be merged unless CI is green.poetry run prek run --all-filespasses (lint, format, and type checks).