Skip to content

Combining CurlClient with StopwatchPlugin causes Promise onRejected handler to never be invoked #26

Closed
@StephenClouse

Description

@StephenClouse

Not sure which project to file this under, but curl-client seems the most appropriate as this behavior does not occur with guzzle6-adapter.

Basically, if the Stopwatch plugin is attached to the client (as it would be in a default configuration running under Symfony with httplug-bundle), the CurlClient ignores the reject handler on any request.

Test script:

use Http\Client\Curl\Client;
use Http\Client\Common\PluginClient;
use Http\Client\Common\Plugin\ErrorPlugin;
use Http\Client\Common\Plugin\StopwatchPlugin;
use GuzzleHttp\Psr7\Request;
use Symfony\Component\Stopwatch\Stopwatch;

$clients = [
    'normal_client' => new PluginClient(new Client(), [
        new ErrorPlugin()
    ]),
    'stopwatch_client' => new PluginClient(new Client(), [
        new ErrorPlugin(),
        new StopwatchPlugin(new Stopwatch()),
    ]),
];

$urls = [
    'http://www.google.com/',
    'http://localhost:8000/asdfasdfasddf',
    'http://www.nosuch.domain/foo'
];
$promises = [];

foreach ($clients as $clientName => $client) {
    foreach ($urls as $url) {
        $promises[] = $client->sendAsyncRequest(new Request('GET', $url))
               ->then(
                    function ($response) use ($clientName, $url) {
                        echo "[$clientName] $url SUCCESS " . $response->getStatusCode() . ' ' . $response->getReasonPhrase() . "\n";
                    }, function ($e) use ($clientName, $url) {
                        echo "[$clientName] $url ERROR " . $e->getMessage() . "\n";
                    }
                );
    }
}

foreach ($promises as $promise) {
    try {
        $promise->wait();
    } catch (\Exception $e) {
    }
}

Expected output:

[normal_client] http://www.nosuch.domain/foo ERROR Could not resolve host: www.nosuch.domain
[normal_client] http://localhost:8000/asdfasdfasddf ERROR Not Found
[normal_client] http://www.google.com/ SUCCESS 200 OK
[stopwatch_client] http://www.nosuch.domain/foo ERROR Could not resolve host: www.nosuch.domain
[stopwatch_client] http://localhost:8000/asdfasdfasddf ERROR Not Found
[stopwatch_client] http://www.google.com/ SUCCESS 200 OK

Actual output:

[normal_client] http://www.nosuch.domain/foo ERROR Could not resolve host: www.nosuch.domain
[normal_client] http://localhost:8000/asdfasdfasddf ERROR Not Found
[normal_client] http://www.google.com/ SUCCESS 200 OK
[stopwatch_client] http://www.google.com/ SUCCESS 200 OK

If you swap out Curl\Client for Guzzle6\Client, the expected output (with slightly different error messages) is seen.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions