8000 `Could not contact DNS servers` after a connection outage and re-establishment · Issue #124 · aio-libs/aiodns · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Could not contact DNS servers after a connection outage and re-establishment #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mberdyshev opened this issue Oct 10, 2024 · 9 comments · Fixed by #145
Closed

Could not contact DNS servers after a connection outage and re-establishment #124

mberdyshev opened this issue Oct 10, 2024 · 9 comments · Fixed by #145

Comments

@mberdyshev
Copy link

I changed the example from the repository description to provide infinite query retries until a successful answer:

import asyncio
import aiodns

loop = asyncio.SelectorEventLoop()
resolver = aiodns.DNSResolver(loop=loop)

async def query(name, query_type):
    while True:
        try:
            return await resolver.query(name, query_type)
        except aiodns.error.DNSError as err:
            print(err)
            await asyncio.sleep(1)

coro = query('google.com', 'A')
result = loop.run_until_complete(coro)
print(result)
loop.close()

Let's assume my Windows machine has some network problems before the script run - I mockup this with the following cmd command:

netsh wlan add filter permission=block ssid="<Wi-Fi ssid>" networktype=infrastructure

When the script starts it constantly outputs (11, 'Could not contact DNS servers') as expected. But even if the network connection is re-established (netsh wlan delete filter <...>) during the script run, it still outputs the error. I can get the answer only if I stop and rerun the script.

I have also opened the issue on pycares tracker - saghul/pycares#203 .

@bdraco
Copy link
Member
bdraco commented Oct 10, 2024

The channel is probably being initialized with no nameservers, and then the connection comes online the nameservers are populated, but the channel isn't being recreated

@bdraco
Copy link
Member
bdraco commented Oct 10, 2024

When the system config changes, https://c-ares.org/docs/ares_reinit.html needs to be called on the channel

@bdraco
Copy link
Member
bdraco commented Oct 10, 2024

To fix this

area_reinit needs to be exposed in pycares and than aiodns.DNSResolver needs a reinit method.

Then you need to call that method when the network changes

@Dreamsorcerer
Copy link
Member

Is there a possibility this can be done automatically? Seems like a bit of an issue if we expect every developer to implement this themselves in order to have a robust application.

@saghul
Copy link
Contributor
saghul commented Oct 11, 2024

Not sure how TBH. THat's a question for the c-ares project likely...

@bdraco
Copy link
Member
bdraco commented Oct 11, 2024

Is there a possibility this can be done automatically? Seems like a bit of an issue if we expect every developer to implement this themselves in order to have a robust application.

Every operating system is different on how it knows the network has changed. I'm not aware of any python library that can abstract that away and watch for network changes on all or even most systems

@bdraco
Copy link
Member
bdraco commented Apr 29, 2025

Started working on adding a reinit method in the stack saghul/pycares#219

bdraco added a commit to bdraco/pycares that referenced this issue Apr 29, 2025
bdraco added a commit to bdraco/pycares that referenced this issue Apr 29, 2025
@bdraco
Copy link
Member
bdraco commented May 2, 2025

@mberdyshev 3.3.0 should take care of this issue.

If you are using windows, there are some more fixes from upstream c-ares coming in saghul/pycares#221 once it makes it to a release as there were still some cases on Windows where it wouldn't pickup manual changes.

@mberdyshev
Copy link
Author

I confirm that it works now as expected. Thank you a lot, @bdraco!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
0