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

Timeouts for DNS lookups #79

Closed
jsha opened this issue Jun 21, 2020 · 2 comments
Closed

Timeouts for DNS lookups #79

jsha opened this issue Jun 21, 2020 · 2 comments

Comments

@jsha
Copy link
Collaborator

jsha commented Jun 21, 2020

Right now ureq has no way to time out DNS lookups. It uses to_socket_addrs, which says:

Note that this function may block the current thread while resolution is performed.

Under the hood, I believe this uses getaddrinfo on Linux, which does not allow setting a timeout.

Some documentation about how curl handles this is here: https://github.com/curl/curl/blob/26d2755d7c3181e90e46014778941bff53d2309f/lib/hostip.c#L91-L115. It sounds like the options are:

  • Use an asynchronous resolver (probably not an option for us).
  • Run the resolve in a thread. Currently the only place ureq uses threads outside of tests is when handling a socks stream, and there's a comment on that code that suggests it would be better to set a read timeout on the upstream socks implementation. But some judicious use of threads in ureq is probably not a bad idea.
  • Use alarm() / SIGALRM. It can only set alarms in units of seconds, and curl mentions there might be some compatibility problems due to running the rest of the program in a signal handler: https://github.com/curl/curl/blob/26d2755d7c3181e90e46014778941bff53d2309f/lib/hostip.c#L625-L637

This may not be a terribly big priority because in practice getaddrinfo does have built-in timeouts on many systems. For instance, on Linux the default config has a timeout of 5s for name resolution. The Windows default is 15s.

@algesten
Copy link
Owner

algesten commented Dec 9, 2023

Related to #618

@algesten
Copy link
Owner

This is solved in ureq 3.x

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