Random "couldn't resolve host" failures in curl_multi

From: Date: Mon, 02 Sep 2019 16:16:22 +0000
Subject: Random "couldn't resolve host" failures in curl_multi
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222525@lists.php.net to get a copy of this message
Hello! I'm experiencing a pretty random failure of curl_multi to grab some of the handles added to it. I've already reported it to devs of libcurl, but they told me to toss this hot potato back here, as apparently curl_multi_exec is php7-curl's wrapper around libcurl's curl_multi_perform and any faults must lie in there. So, the matter at hand. I create 12 handles for http:// URLs, all using the same target machine, just different files. I add them to curl_multi. And as soon as I curl_multi_exec, randomly sometimes they all work, and sometimes only exactly first 8 get fetched, others don't even show up in curl_multi_select active count and appear to get silently ignored. After making a proper error-checking setup with curl_multi_info_read, I found that some of the handles get a "couldn't resolve host name" message queued, right on the very first call to curl_multi_exec. However, the error is not recorded in the child handles - the skipped ones return 0 for curl_errno. Also, it's always the final handles that fail - n first handles work, n+1 till the end fail to resolve, with n sometimes being all 12, sometimes 8, a few times 4, but I also caught it on 11. This is in cURL 7.62 under PHP 7.2.21. Simplified code to illustrate this would go: $cm = curl_multi_init() for ($i=1;i<=12;i++) { $handles[$i] = curl_init ("http://the.same.host.com/file" . $i); curl_multi_add_handle ( $cm, $handles[$i]); } $status = curl_multi_exec ($cm, $still_running) // $status gets 0, $still_running gets 8. $info = curl_multi_info_read ($cm, $queue) // $info contains 6 = "couldn't resolve host" for handle 9, $queue shows 3 as there are also failures for handles 10, 11 and 12 $error = curl_errno ($handles[9]) // $error is 0 $info = curl_getinfo ($handles[9]) // pretty much empty structure, basically all 0s So here are my 2 questions: - what could be causing this to happen randomly? Each page reload it either gets all 12 correctly, most often it gets 8, rarely gets just 4, and even more rarely other numbers. - why isn't the error stored in the child handle? I'd assume any error thrown in curl_multi, no matter why it occurred, would get set for curl_getinfo to retrieve. Regards, -- Adam "Sinus" Skawiński

« previous php.bugs (#222525) next »