php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74334 multicurl infinite loop
Submitted: 2017-03-29 15:02 UTC Modified: 2019-03-26 11:56 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: julien at palard dot fr Assigned:
Status: Not a bug Package: cURL related
PHP Version: Irrelevant OS: Debian GNU/Linux 8.7 (jessie)
Private report: No CVE-ID: None
 [2017-03-29 15:02 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-29 15:07 UTC] julien at palard dot fr
Follow-up: I tried replacing domain names by IP addresses and it works, so it may be related to name resolution.
 [2018-04-07 09:14 UTC] sean dot bailey at gmail dot com
I can confirm this is happening on Fedora 27 as well.
 [2019-03-26 11:56 UTC] mike@php.net
-Status: Open +Status: Not a bug
 [2019-03-26 11:56 UTC] mike@php.net
It's polling the connect to lxr.php.net, which seems to be down/filtered -- set a reasonable connect timeout and the transfer will abort within a shorter time frame.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 22:01:30 2024 UTC