You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
waiting for name resolver threads before quitting can cause delays even with --max-time #2975
time curl https://github.com/ --max-time 1 -v
And curl exits after 5 seconds. The output is
time curl https://github.com/ --max-time 1 -v
* Resolving timed out after 1000 milliseconds
* Could not resolve host: github.com
* stopped the pause stream!
* Closing connection 0
curl: (28) Resolving timed out after 1000 milliseconds
curl https://github.com/ --max-time 1 -v 0.02s user 0.02s system 0% cpu 5.042 total
I expected the following
curl exits after 1 second.
Document at https://ec.haxx.se/usingcurl-timeouts.html says "When the set time has elapsed, curl will exit no matter what is going on at that moment", so I think this is a bug.
I'm not sure why that is necessary because libcurl threaded resolver was designed to handle cleaning up the resolves in the background, which would happen later on when multi_done calls via Curl_resolver_cancel and in this case that would call asyn-thread's destroy_async_data
When the application just started the transfer and then stops it while
the name resolve in the background thread hasn't completed, we need to
wait for the resolve to complete and then cleanup data accordingly.
Enabled test 1553 again and added test 1590 to also check when the host
name resolves successfully.
Detected by OSS-fuzz.
Closes #1968
Leaking is a problem for tools that trigger on this (like OSS-Fuzz did) and for applications who'd do this several times. I don't think we can allow that to happen unconditionally. But also not responding sooner to this sort of failure is also disturbing...
If the thread can be abandoned with ownership of all its resources which it later cleans up itself (I'm assuming here) then I don't see what benefit there is to waiting for it other than to please OSS-Fuzz. I think the fuzzer is wrong in this case.
Any wait for the pending thread(s) will risk blocking a call that will effect some users. We can only really fix this issue by removing the wait completely. If the threads don't leak any memory by this, I think it can be done. We just have to keep logic to make sure the OSS-Fuzz and possibly other tests don't consider that a leak.
changed the title [-]option --max-time is ineffective when DNS timeout[/-][+]waiting for name resolver threads before quitting can cause delays even with --max-time[/+]on Oct 18, 2018
If the threads don't leak any memory by this, I think it can be done.
Threads leak their stacks.
This issue can't be fully fixed in libcurl, but users of libcurl (e.g. the command line curl tool) should be able to clean up by invoking exit() instead of curl_multi_cleanup(). GNU cp command does exactly this, when it isn't built for Valgrind.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I also encountered this issue.
I'm currently building a PHP application, accessing an external API while the user requests the page. In order to not slow down the page speed in case of any problems with the API, I want to skip the api call after a certain timeout. For that I set CURLOPT_TIMEOUT_MS to 150. Unfortunately this doesn't worked reliably. Since we faced issues with the external API or better said, with the dns resolving, I often got this error: Resolving timed out after 252 milliseconds. I've no idea where the 252 ms comes from, but not that 252ms is already too much, I saw the requests in the end takes even longer. For example when the average request took 500ms, some requests took 1200ms or even 1500ms which should never happen if the timeout would be adhered.
My guess: even that were seems to be a timeout of 252ms for the dns resolving, this timeout will be ignored. This could be valid since I figured out with dig that the dns resolving some times really took 500ms or longer.
Since I put the domain in the /etc/hosts the page speed is much more stable.
Activity
jay commentedon Sep 11, 2018
Yes in your case it calls getaddrinfo which is blocking in a separate thread, however it waits in multi_done for the resolve to complete:
curl/lib/multi.c
Lines 536 to 539 in 432eb5f
I'm not sure why that is necessary because libcurl threaded resolver was designed to handle cleaning up the resolves in the background, which would happen later on when multi_done calls via Curl_resolver_cancel and in this case that would call asyn-thread's destroy_async_data
curl/lib/asyn-thread.c
Lines 351 to 362 in 432eb5f
jay commentedon Sep 11, 2018
git blame puts it at ac9a179
I think we should just let it leak
bagder commentedon Sep 11, 2018
This isn't easy.
Leaking is a problem for tools that trigger on this (like OSS-Fuzz did) and for applications who'd do this several times. I don't think we can allow that to happen unconditionally. But also not responding sooner to this sort of failure is also disturbing...
jay commentedon Sep 11, 2018
If the thread can be abandoned with ownership of all its resources which it later cleans up itself (I'm assuming here) then I don't see what benefit there is to waiting for it other than to please OSS-Fuzz. I think the fuzzer is wrong in this case.
alexeip0 commentedon Sep 14, 2018
Perhaps we should track the number of detached threads and have Curl_resolver_global_cleanup wait for the count to drop to 0 before returning?
alexeip0 commentedon Sep 14, 2018
This would have to be rather intricate, since curl_multi_cleanup is called from multi thread as well, thus, cannot do blocking wait.
bagder commentedon Sep 16, 2018
Any wait for the pending thread(s) will risk blocking a call that will effect some users. We can only really fix this issue by removing the wait completely. If the threads don't leak any memory by this, I think it can be done. We just have to keep logic to make sure the OSS-Fuzz and possibly other tests don't consider that a leak.
[-]option --max-time is ineffective when DNS timeout[/-][+]waiting for name resolver threads before quitting can cause delays even with --max-time[/+]Alexander-- commentedon Nov 24, 2018
Threads leak their stacks.
This issue can't be fully fixed in libcurl, but users of libcurl (e.g. the command line
curltool) should be able to clean up by invoking exit() instead of curl_multi_cleanup(). GNUcpcommand does exactly this, when it isn't built for Valgrind.stale commentedon Oct 10, 2019
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
nicolashohm commentedon Nov 11, 2019
I also encountered this issue.
I'm currently building a PHP application, accessing an external API while the user requests the page. In order to not slow down the page speed in case of any problems with the API, I want to skip the api call after a certain timeout. For that I set CURLOPT_TIMEOUT_MS to 150. Unfortunately this doesn't worked reliably. Since we faced issues with the external API or better said, with the dns resolving, I often got this error:
Resolving timed out after 252 milliseconds. I've no idea where the 252 ms comes from, but not that 252ms is already too much, I saw the requests in the end takes even longer. For example when the average request took 500ms, some requests took 1200ms or even 1500ms which should never happen if the timeout would be adhered.My guess: even that were seems to be a timeout of 252ms for the dns resolving, this timeout will be ignored. This could be valid since I figured out with
digthat the dns resolving some times really took 500ms or longer.Since I put the domain in the
/etc/hoststhe page speed is much more stable.I hope this story was helpful for someone!
curl 7.38.0 (x86_64-pc-linux-gnu) libcurl/7.38.0The php script was similar to this:
Don't wait for DNS thread on exit. Fixes curl#2975.
CURLOPT_QUICK_EXIT: don't wait for DNS thread on exit