Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a90a6c9

Browse files
[HttpClient] fix scheduling pending NativeResponse
1 parent 8855082 commit a90a6c9

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

src/Symfony/Component/HttpClient/Internal/NativeClientState.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Symfony\Component\HttpClient\Internal;
1313

14-
use Symfony\Component\HttpClient\Response\NativeResponse;
15-
1614
/**
1715
* Internal representation of the native client's state.
1816
*
@@ -24,8 +22,6 @@ final class NativeClientState extends ClientState
2422
{
2523
/** @var int */
2624
public $id;
27-
/** @var NativeResponse[] */
28-
public $pendingResponses = [];
2925
/** @var int */
3026
public $maxHostConnections = PHP_INT_MAX;
3127
/** @var int */

src/Symfony/Component/HttpClient/Response/NativeResponse.php

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,7 @@ private static function schedule(self $response, array &$runningResponses): void
209209
$runningResponses[$i] = [$response->multi, []];
210210
}
211211

212-
if (null === $response->remaining) {
213-
$response->multi->pendingResponses[] = $response;
214-
} else {
215-
$runningResponses[$i][1][$response->id] = $response;
216-
}
212+
$runningResponses[$i][1][$response->id] = $response;
217213

218214
if (null === $response->buffer) {
219215
// Response already completed
@@ -315,25 +311,30 @@ private static function perform(NativeClientState $multi, array &$responses = nu
315311
return;
316312
}
317313

318-
if ($multi->pendingResponses && \count($multi->handles) < $multi->maxHostConnections) {
319-
// Open the next pending request - this is a blocking operation so we do only one of them
320-
/** @var self $response */
321-
$response = array_shift($multi->pendingResponses);
322-
$response->open();
323-
$responses[$response->id] = $response;
324-
$multi->sleep = false;
325-
self::perform($response->multi);
326-
327-
if (null !== $response->handle) {
328-
$multi->handles[] = $response->handle;
314+
// Create empty activity lists to tell ResponseTrait::stream() we still have pending requests
315+
foreach ($responses as $i => $response) {
316+
if (null === $response->remaining && null !== $response->buffer) {
317+
$multi->handlesActivity[$i] = [];
329318
}
330319
}
331320

332-
if ($multi->pendingResponses) {
333-
// Create empty activity list to tell ResponseTrait::stream() we still have pending requests
334-
$response = $multi->pendingResponses[0];
335-
$responses[$response->id] = $response;
336-
$multi->handlesActivity[$response->id] = [];
321+
if (\count($multi->handles) >= $multi->maxHostConnections) {
322+
return;
323+
}
324+
325+
// Open the next pending request - this is a blocking operation so we do only one of them
326+
foreach ($responses as $i => $response) {
327+
if (null === $response->remaining && null !== $response->buffer) {
328+
$response->open();
329+
$multi->sleep = false;
330+
self::perform($multi);
331+
332+
if (null !== $response->handle) {
333+
$multi->handles[] = $response->handle;
334+
}
335+
336+
break;
337+
}
337338
}
338339
}
339340

0 commit comments

Comments
 (0)