Skip to content
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

dns.asyncresolver timeout #637

Closed
LizardBlizzard opened this issue Feb 18, 2021 · 5 comments
Closed

dns.asyncresolver timeout #637

LizardBlizzard opened this issue Feb 18, 2021 · 5 comments

Comments

@LizardBlizzard
Copy link

Hi,
While experimenting with dns.asyncresolver I encountered an error which occurs only on my Windows 10 machine and not on WSL or other Linux hosts.

Running the following code throws a timeout exception:

import asyncio
import dns.asyncresolver
import dns.asyncbackend
import dns.exception
from typing import List


async def asyncquery(target, type="A"):
    record_type = "A"
    resolver = dns.asyncresolver.Resolver()
    resolver.nameservers = ["1.1.1.1", "8.8.8.8"]
    resolver.timeout = 10.0
    resolver.lifetime = 10.0

    try:
        answers = await resolver.resolve(target, rdtype=record_type)
        records = [rdata for rdata in answers]
    except dns.resolver.NoAnswer:
        print(f'{target} query returned no answer')
        return None
    except dns.exception.Timeout:
        print(f'{target} query timed out')
        return None
    return records


if __name__ == "__main__":
    target = "google.com"
    res = asyncio.run(asyncquery(target, "A"))
    if res:
        print(f"Results")
        for r in res:
            print(r)

I do see a valid response in Wireshark, but it doesn't seem to be captured by Python.
תמונה

The non-async resolver works just fine though 🤷‍♀️

Python version: 3.9.1
dnspython: 2.1.0

Any ideas what can cause this?

Thanks for the help!

@rthalley
Copy link
Owner

I am no windows expert at all, but I ran this on a windows server 2019 vm and saw the same error you did. I added a bunch of debugging and it looks like loop.create_datagram_endpoint() is generating an error that fails the protocol. The protocol thus never completes, and you get a timeout. The error is "[WinError 10022] An invalid argument was supplied". AFAIK this is not any of the arguments I supplied, and I'm wondering if this is possibly a regression in Python 3.9. Before I had unfixable-by-me Azure problems, we tested dnspython on Windows and all of the async stuff worked.

I might try to look into this more, but if you try using "trio" or "curio" for async stuff, they still work. I like either of them a lot better than asyncio, so if you don't need asyncio, you might check them out!

@rthalley rthalley added the Bug label Feb 19, 2021
rthalley added a commit that referenced this issue Feb 26, 2021
asyncio on Windows requries connected sockets.  [Issue #637]
@rthalley rthalley added this to Done in 2.1.1 Feb 26, 2021
@rthalley rthalley added the Fixed label Feb 26, 2021
@rthalley rthalley added this to Done in 2.2 Feb 26, 2021
@rthalley
Copy link
Owner

fixed.

@LizardBlizzard
Copy link
Author

@rthalley Thanks, new version works like a charm!

@altendky
Copy link

altendky commented Nov 1, 2021

Any expectations of releasing 2.1.1 or 2.2? I don't see tags nor releases on PyPI.

@rthalley
Copy link
Owner

rthalley commented Nov 2, 2021

I'm aiming for 2.2 by the end of the year. No 2.1.1.

rthalley added a commit that referenced this issue Dec 15, 2023
recvfrom().

The fix for [#637] erroneously concluded that that windows asyncio
needed connected datagram sockets, but subsequent further
investation showed that the actual problem was that windows wants
an unconnected datagram socket to be bound before recvfrom is called.
Linux autobinds in this case to the wildcard address and port, so
that's why we didn't see any problems there.  We now ensure that
the source is bound.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
2.1.1
Done
2.2
Done
Development

No branches or pull requests

3 participants