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

it looks like some socket methods can block doing dns resolution? #118

Closed
njsmith opened this issue Jun 15, 2020 · 3 comments
Closed

it looks like some socket methods can block doing dns resolution? #118

njsmith opened this issue Jun 15, 2020 · 3 comments

Comments

@njsmith
Copy link
Collaborator

njsmith commented Jun 15, 2020

I was just investigating some performance issues in trio, and in the process noticed an issue in curio that it looks like anyio might share: anywhere you accept a socket address and pass it through to the stdlib socket module, the socket module will happily accept a hostname and then do a blocking DNS lookup. This is pretty annoying, but whaddaygonnado.

Asyncio and Trio both handle this by automatically resolving hostnames on their own, before passing them to the stdlib socket module. Curio doesn't seem to handle it, and I guess expects the user to pre-resolve all hostnames.

Looking at the v1 code currently, I think anyio's bind method does use a thread when it detects that the address has a hostname in it, but all the other methods that take addresses – connect, sendto, etc. – all pass the address through to stdlib socket directly, so can accidentally block doing DNS lookups.

@agronholm
Copy link
Owner

You may be right about sendto(), but connect_tcp does a DNS lookup in a thread first, and only passes raw addresses to sock.connect().

@njsmith
Copy link
Collaborator Author

njsmith commented Jun 15, 2020

Oh, so sock.connect is a private/internal API?

@agronholm
Copy link
Owner

Yup. I'm still trying to figure out if asyncio is capable of supporting an async socket abstraction via transports and protocols, but until then, the internal Socket class is private.

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

No branches or pull requests

2 participants