Bug #74334 [Com]: multicurl infinite loop
[email protected] ("julien at palard dot fr")
| Newsgroups | php.bugs |
|---|---|
| Message-ID | <[email protected]> |
Edit report at https://bugs.php.net/bug.php?id=74334&edit=1
ID: 74334
Comment by: julien at palard dot fr
Reported by: julien at palard dot fr
Summary: multicurl infinite loop
Status: Open
Type: Bug
Package: cURL related
Operating System: Debian GNU/Linux 8.7 (jessie)
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Follow-up: I tried replacing domain names by IP addresses and it works, so it may be related to name resolution.
Previous Comments:
------------------------------------------------------------------------
[2017-03-29 15:02:25] julien at palard dot fr
Description:
------------
Copying and pasting the example on http://php.net/manual/en/function.curl-multi-init.php give an infinite loop on:
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($mh) != -1) {
because curl_multi_select always returns -1.
I tried stracing but found nothing relevant, there's no syscall during the infinite loop, just before the loop I'm getting:
[pid 11348] 1490799411.296356 close(8) = 0
[pid 11348] 1490799411.296397 madvise(0x7f425f426000, 8368128, MADV_DONTNEED) = 0
[pid 11348] 1490799411.296428 exit(0) = ?
[pid 11348] 1490799411.296473 +++ exited with 0 +++
[pid 11347] 1490799411.359286 <... poll resumed> ) = 1 ([{fd=9, revents=POLLIN}])
[pid 11347] 1490799411.359362 ioctl(9, FIONREAD, [501]) = 0
[pid 11347] 1490799411.359438 recvfrom(9, "\22>\201\200\0\1\0\2\0\r\0\f\3lxr\3php\3net\0\0\1\0\1\300\f\0"..., 2048, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("167.[redacted].1")}, [28->16]) = 501
[pid 11347] 1490799411.359594 poll([{fd=9, events=POLLIN}], 1, 4915) = 1 ([{fd=9, revents=POLLIN}])
[pid 11347] 1490799411.469988 ioctl(9, FIONREAD, [105]) = 0
[pid 11347] 1490799411.470060 recvfrom(9, "|b\201\200\0\1\0\1\0\1\0\0\3lxr\3php\3net\0\0\34\0\1\300\f\0"..., 65536, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("167.[redacted].1")}, [28->16]) = 105
[pid 11347] 1490799411.470150 close(9) = 0
[pid 11347] 1490799411.470231 madvise(0x7f425fc27000, 8368128, MADV_DONTNEED) = 0
[pid 11347] 1490799411.470284 exit(0) = ?
[pid 11347] 1490799411.470346 +++ exited with 0 +++
The presence of [pid …] means that they are forks, not the main process, which is looping.
Tested on 7.0.16-3 and 5.6.30-0+deb8u1 (from Debian packages).
Test script:
---------------
The example on http://php.net/manual/en/function.curl-multi-init.php which is:
<?php
// create both cURL resources
$ch1 = curl_init();
$ch2 = curl_init();
// set URL and other appropriate options
curl_setopt($ch1, CURLOPT_URL, "http://lxr.php.net/");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/");
curl_setopt($ch2, CURLOPT_HEADER, 0);
//create the multiple cURL handle
$mh = curl_multi_init();
//add the two handles
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);
$active = null;
//execute the handles
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($mh) != -1) {
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
//close the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);
?>
Expected result:
----------------
An error or a result.
Actual result:
--------------
An infinite loop.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74334&edit=1