Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

DNS cache in aiohttp.TCPConnector causes client requests to timeout when host address changes #11

Closed
hanula opened this issue Feb 10, 2017 · 2 comments

Comments

@hanula
Copy link
Contributor

hanula commented Feb 10, 2017

Hi!

Using domain-based elasticsearch hosts that change their IP over time can cause AsyncElasticsearch client to timeout requests as the default DNS cache resolves the hostname with old address.

For example, with Elasticsearch Heroku Add-ons that run on AWS, the host URL doesn't change and looks like https://abcdef-123455.eu-west-1.bonsaisearch.net, but the IP address can change over time. Because of the DNS cache - which isn't flushed - the client tries to send requests to wrong host IP and failes.

Solution might be to pass explicit use_dns_cache param to aiohttp.TCPConnector in the constructor of AIOHttpConnection.
Additionally, because of the default DNS resolver being thread-based, a dns_resolver param could be used to specify own, for example aiodns-based AsyncResolver, although it was removed as default one because of compatibility issues with IPv6 systems.

I can submit a PR with this solution soon.
What do you think?

@honzakral
Copy link
Contributor

Hi,

thank you very much for the report. The default that we choose should be the safest option that works everywhere (turning off DNS cache in this case).

We can then provide additional options to improve performance/experience in some circumstances, but that is not the highest priority, especially if this can be implemented as a "plugin" - a custom subclass of the Connection class we are using.

A PR would be most welcome!

Thank you,
Honza

@honzakral
Copy link
Contributor

Released as 5.1.0

michalc added a commit to uktrade/activity-stream that referenced this issue Aug 14, 2018
Sentry sometimes shows similar timeouts to the ones reported at

    elastic/elasticsearch-py-async#11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants