Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpClient] Strange behavior of pause_handler with CurlHttpClient #53622

Copy link
Copy link
Closed
@HypeMC

Description

@HypeMC
Issue body actions

Symfony version(s) affected

6.4+ (probably earlier as well)

Description

I'm experiencing strange behavior when using the pause_handler with the CurlHttpClient. In the case of multiple requests, the pause_handler doesn't always work, eg:

$httpClient = new CurlHttpClient();

/** @var ResponseInterface[] $requests */
$requests = [];
for ($i = 0; $i < 100; $i++) {
    $requests[] = $httpClient->request('GET', 'http://localhost:8080/ping');
}

$time = 5;
foreach ($requests as $request) {
    $request->getInfo('pause_handler')($time);
    $time += 5;
}

foreach ($requests as $request) {
    $output->writeln($request->getContent());
}
2024-01-24T02:30:54.847983
2024-01-24T02:30:46.548562
2024-01-24T02:30:46.467222
2024-01-24T02:30:46.439153
2024-01-24T02:30:46.494591
2024-01-24T02:30:46.521667
2024-01-24T02:30:46.392766
2024-01-24T02:30:46.574905
2024-01-24T02:30:55.835802
2024-01-24T02:30:47.606177
2024-01-24T02:30:47.578046
2024-01-24T02:30:47.547933

However, if I set the pause_handler earlier, everything works as expected:

$httpClient = new CurlHttpClient();

/** @var ResponseInterface[] $requests */
$requests = [];
$time = 5;
for ($i = 0; $i < 100; $i++) {
    $requests[] = $request = $httpClient->request('GET', 'http://localhost:8080/ping');
    $request->getInfo('pause_handler')($time);
    $time += 5;
}

foreach ($requests as $request) {
    $output->writeln($request->getContent());
}
2024-01-24T02:33:30.222284
2024-01-24T02:33:35.223621
2024-01-24T02:33:40.223094
2024-01-24T02:33:45.218890
2024-01-24T02:33:50.208427
2024-01-24T02:33:55.208496
2024-01-24T02:34:00.207538
2024-01-24T02:34:05.221313
2024-01-24T02:34:10.209738
2024-01-24T02:34:15.210125
2024-01-24T02:34:20.211701
2024-01-24T02:34:25.207769

The problem seems to be caused by the following code:

if ($execCounter === $multi->execCounter) {
$multi->execCounter = !\is_float($execCounter) ? 1 + $execCounter : \PHP_INT_MIN;
curl_multi_remove_handle($multi->handle, $ch);
}

I'm not really sure what this code is meant to do or if this is expected behavior.

It should be noted that the NativeHttpClient always works as expected.

How to reproduce

I've create an example application: example.zip

composer install
symfony serve --port 8080 (or php -S localhost:8080 public/)

bin/console app:ping-not-ok
bin/console app:ping-ok

Possible Solution

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.