Description
Symfony version(s) affected: 5.1.3
Description
Httplug adapter in symfony/http-client seems to behave incorrectly when some combinations of chaining of promises is used. The example is provided below, where in presence of both ->then
combinators script throws GuzzleHttp\Promise\RejectionException: The promise was rejected with reason: Invoking the wait callback did not resolve the promise
instead of printing status code. If any of the ->then
calls is eliminated the program behaves as expected.
How to reproduce
Run composer require symfony/http-client php-http/httplug nyholm/psr7 guzzlehttp/promises
, then execute following script:
<?php
use Psr\Http\Message\ResponseInterface;
use Symfony\Component\HttpClient\CurlHttpClient;
use Symfony\Component\HttpClient\HttplugClient;
require __DIR__ . '/vendor/autoload.php';
$client = new HttplugClient(new CurlHttpClient());
$sendAsyncRequest = function () use ($client): Http\Promise\Promise {
return $client->sendAsyncRequest($client->createRequest('GET', 'https://example.com'));
};
$response = $sendAsyncRequest()
->then($sendAsyncRequest)
->then(function (ResponseInterface $response): ResponseInterface { return $response; })
->wait();
echo $response->getStatusCode() . "\n";
Additional context
Bug seems to be somewhere in HttplugClient promises handling as it manifests as well with native and amp http clients.