Aiohttp: AsyncResolver not default when aiodns is installed.

Created on 26 Aug 2017  路  6Comments  路  Source: aio-libs/aiohttp

Long story short

The docs say the AsyncResolver is the default resolver used when aiodns is installed but this is not really the case.

Here's what current stable docs say:

Changed in version 1.0: The resolver is aiohttp.AsyncResolver now if aiodns is installed.

Expected behaviour

AsyncResolver being the default resolver when aiodns is installed.

Actual behaviour

ThreadedResolver is used.

Steps to reproduce

  1. Install aiodns: pip install aiodns.
  2. Check if AsyncResolver is default:
    >>> aiohttp.resolver.DefaultResolver == aiohttp.resolver.AsyncResolver
    False
    >>> aiohttp.resolver.DefaultResolver == aiohttp.resolver.ThreadedResolver
    True

Your environment

I'm using aiohttp version 2.2.3 with Python 3.5.2 on Ubuntu 16.04.3.

More observations

In /aiohttp/resolver.py we can clearly see this line:

aiodns_default = False

And then later on:

DefaultResolver = AsyncResolver if aiodns_default else ThreadedResolver
outdated

Most helpful comment

thanks @asvetlov .
So when using a session, the way to do it is by passing it a connector with async resolver? i.e.
ClientSession(connector=aiohttp.TCPConnector(resolver=aiohttp.AsyncResolver()))

All 6 comments

Doc should reflect current state.
See #559 for information about disabling async resolver by default.

Is it possible to explicitly set async resolver globally, or does it need to be set for each client session?

No global state :)
Usually you should not create too many sessions but do it in very little places in your program.

thanks @asvetlov .
So when using a session, the way to do it is by passing it a connector with async resolver? i.e.
ClientSession(connector=aiohttp.TCPConnector(resolver=aiohttp.AsyncResolver()))

Yes

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].

Was this page helpful?
0 / 5 - 0 ratings