Skip to content

CURL is stuck in invalid state after DNS resolution failure #18216

@devgs

Description

@devgs

I did this

There seems to be some broken state in CURL handle. To enter this state the request must fail in DNS resolution. Specifically in our case the DNS server goes down and doesn't respond for some time.

In older versions of cURL the subsequent attempt to reuse handle (keep-alive) in this broken state immediately (no delays) leads to an CURLE_BAD_FUNCTION_ARGUMENT error. The only option is to just drop this state, because the curl_easy_reset() doesn't have any effect.

In the most recent version (and several earlier versions that I checked, as well) behavior is a bit different. Request fails with timeout in DNS but then all subsequent requests to the same CURL handle, again hang for a duration of configured timeout value and then fail with CURLE_OPERATION_TIMEDOUT. As in older versions, curl_easy_reset() has no effect and the only option is to discard such CURL handle.

I've tracked down the issue to ares. It seems that after the original failure on timeout and call to ares_cancel() the ares channel itself stays in an invalid state. Seems that its internal socket is still open but isn't operable. On call to Curl_ares_getsock() we get its file descriptor and a request to poll it to become readable. But it never does and we basically always wait until the timeout is exhausted.

It seems that in this specific case, when DNS resolution is timed out, the ares channel must be closed, at least in curl_easy_reset(). Otherwise we may end up with a permanently broken state.

I expected the following

I expect CURL handle to not become broken.

curl/libcurl version

curl 8.5.0
curl 8.14.1
curl 8.15.0

operating system

FreeBSD 14.0
FreeBSD 14.2

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions