[HttpClient] fix scheduling pending NativeResponse
This commit is contained in:
parent
8855082ffd
commit
a90a6c9c48
@ -11,8 +11,6 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\HttpClient\Internal;
|
namespace Symfony\Component\HttpClient\Internal;
|
||||||
|
|
||||||
use Symfony\Component\HttpClient\Response\NativeResponse;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal representation of the native client's state.
|
* Internal representation of the native client's state.
|
||||||
*
|
*
|
||||||
@ -24,8 +22,6 @@ final class NativeClientState extends ClientState
|
|||||||
{
|
{
|
||||||
/** @var int */
|
/** @var int */
|
||||||
public $id;
|
public $id;
|
||||||
/** @var NativeResponse[] */
|
|
||||||
public $pendingResponses = [];
|
|
||||||
/** @var int */
|
/** @var int */
|
||||||
public $maxHostConnections = PHP_INT_MAX;
|
public $maxHostConnections = PHP_INT_MAX;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
|
@ -209,11 +209,7 @@ final class NativeResponse implements ResponseInterface
|
|||||||
$runningResponses[$i] = [$response->multi, []];
|
$runningResponses[$i] = [$response->multi, []];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $response->remaining) {
|
$runningResponses[$i][1][$response->id] = $response;
|
||||||
$response->multi->pendingResponses[] = $response;
|
|
||||||
} else {
|
|
||||||
$runningResponses[$i][1][$response->id] = $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $response->buffer) {
|
if (null === $response->buffer) {
|
||||||
// Response already completed
|
// Response already completed
|
||||||
@ -315,25 +311,30 @@ final class NativeResponse implements ResponseInterface
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($multi->pendingResponses && \count($multi->handles) < $multi->maxHostConnections) {
|
// Create empty activity lists to tell ResponseTrait::stream() we still have pending requests
|
||||||
// Open the next pending request - this is a blocking operation so we do only one of them
|
foreach ($responses as $i => $response) {
|
||||||
/** @var self $response */
|
if (null === $response->remaining && null !== $response->buffer) {
|
||||||
$response = array_shift($multi->pendingResponses);
|
$multi->handlesActivity[$i] = [];
|
||||||
$response->open();
|
|
||||||
$responses[$response->id] = $response;
|
|
||||||
$multi->sleep = false;
|
|
||||||
self::perform($response->multi);
|
|
||||||
|
|
||||||
if (null !== $response->handle) {
|
|
||||||
$multi->handles[] = $response->handle;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($multi->pendingResponses) {
|
if (\count($multi->handles) >= $multi->maxHostConnections) {
|
||||||
// Create empty activity list to tell ResponseTrait::stream() we still have pending requests
|
return;
|
||||||
$response = $multi->pendingResponses[0];
|
}
|
||||||
$responses[$response->id] = $response;
|
|
||||||
$multi->handlesActivity[$response->id] = [];
|
// Open the next pending request - this is a blocking operation so we do only one of them
|
||||||
|
foreach ($responses as $i => $response) {
|
||||||
|
if (null === $response->remaining && null !== $response->buffer) {
|
||||||
|
$response->open();
|
||||||
|
$multi->sleep = false;
|
||||||
|
self::perform($multi);
|
||||||
|
|
||||||
|
if (null !== $response->handle) {
|
||||||
|
$multi->handles[] = $response->handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user