-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Connect timeout never set in cURL, hanging longer than timeout/max_duration on unavailable hosts #47246
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
Comments
As far as I tested correctly, this is unrelated to not being able to set the option. Even this simple script runs in 5s no matter what: $h = curl_init('http://unknown.local:1080/messages');
curl_setopt_array($h, [
CURLOPT_CONNECTTIMEOUT => 2,
CURLOPT_TIMEOUT => 2,
]);
curl_exec($h); strace-ing the scripts, it shows many This looks like a curl issue to me. Note that not being able to set the option is on purpose: the API of HttpClient already provides precise control over timeouts, via the timeout+max_duration options for general config, and via BUT, this is hidden by this futex, and I don't know how to work around it... |
I could reproduce a 5 second wait time on MacOS, regardless of the set timeout value. This case could be reproduced in php call or using command line curl connecting to |
Closing as this is not related to HttpClient. |
@nicolas-grekas this still is an issue if DNS resolves but the target port is not open: $h = curl_init('http://172.67.72.38:1080');
curl_setopt_array($h, [
CURLOPT_CONNECTTIMEOUT => 2,
CURLOPT_TIMEOUT => 10,
CURLOPT_VERBOSE => true,
]);
curl_exec($h); gives:
So the curl connection timeout still has an effect in certain situations. We encountered this problem lately in a production environment, where a firewall misconfiguration caused the target port to be blocked. I now figured out, it is not possible to configure connection phase timeouts with Symfony HTTP client using curl. Being able to configure the timeout for the whole request time is not enough, as we want to fail fast on connection errors. At the moment we have to set the request timeout to a relatively high value which does not play well with the retry option. This leads to long waiting times on the user's side before giving up. Would it be possible to reevaluate and eventually allow setting the curl connection timeout again? Thank you very much! |
@deeky666 I suggest you to create a new issue instead of commenting on a closed one (especially when your case is not exactly the same). Opened issues have much more visibility for the community than closed ones. |
@nicolas-grekas agree with @deeky666 here. Even if its a curl error. There is no way to workaround zhis in Symfony http-client, essentially you cannot use it with domains not under your control, which then should be documented as a risk |
@stof i think its the same issue as mine |
Could be fixed by php/php-src#10454 |
@nicolas-grekas that could fix DNS resolution errors but it won't fix situations where DNS resolves but the client is not able to connect to the host (for example because a firewall rule does not allow to connect to that host/port). |
There is nothing we can do about it so 🤷 |
Symfony version(s) affected
4.4.x and higher
Description
In #33022 the CURL_CONNECTTIMEOUT_MS was removed but it was not added to the allow list of
curl.extra
again. As such its not possible to set this setting, causing the default of 5 seconds to be used when connecting to a host that is not available.How to reproduce
Possible Solution
Allow at least to set CURLOPT_CONNECTTIMEOUT_MS in
curl.extra
, but in general at least formax_duration
, it should also setCURLOPT_CONNECTTIMEOUT_MS
in addition toCURLOPT_TIMEOUT_MS
.Additional Context
The text was updated successfully, but these errors were encountered: