Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The promise was rejected: When using ElasticSearch SDK #945

Closed
bensebborn opened this issue Mar 30, 2016 · 3 comments
Closed

The promise was rejected: When using ElasticSearch SDK #945

bensebborn opened this issue Mar 30, 2016 · 3 comments

Comments

@bensebborn
Copy link

We've been successfully trialling the ES service, using the PHP AWS SDK and the ElasticSearch SDK

This was working fine, however today when we've attempted to run the code, we're getting the following:

<br />
<b>Fatal error</b>:  Uncaught exception 'GuzzleHttp\Promise\RejectionException' with message 'The promise was rejected' in /home/vhosts/x.com/vendor/guzzlehttp/promises/src/functions.php:106
Stack trace:
#0 /home/vhosts/x.com/vendor/guzzlehttp/promises/src/RejectedPromise.php(59): GuzzleHttp\Promise\exception_for(Array)
#1 /home/vhosts/x.com/vendor/guzzlehttp/promises/src/Promise.php(65): GuzzleHttp\Promise\RejectedPromise-&gt;wait(true)
#2 /home/vhosts/x.com/httpdocs/search/keywordes.php(62): GuzzleHttp\Promise\Promise-&gt;wait()
#3/home/vhosts/x.com/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(184): {closure}(Array)
#4 /home/vhosts/x.com/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php(159): Elasticsearch\Connections\Connection-&gt;Elasticsearch\Connections\{closure}(Array, Object(Elasticsearch\Connections\Connection), Object(Elasticsearch\Transport), Array)
#5 /home/vhosts/x.com/vendor/elasticsearch/elasticsearch/src/Elasticsear in <b>/home/vhosts/x.com/vendor/guzzlehttp/promises/src/functions.php</b> on line <b>106</b><br />

I have no idea where to start with this error?

Here's a snip of our code (pretty much pulled from docs)

$psr7Handler = Aws\default_http_handler();
$signer = new SignatureV4('es', 'eu-west-1');
$credentialProvider = CredentialProvider::defaultProvider();

// Construct the handler that will be used by Elasticsearch-PHP
$handler = function (array $request) use (
    $psr7Handler,
    $signer,
    $credentialProvider
) {
    // Amazon ES listens on standard ports (443 for HTTPS, 80 for HTTP).
    $request['headers']['host'][0]
        = parse_url($request['headers']['host'][0], PHP_URL_HOST);

    // Create a PSR-7 request from the array passed to the handler
    $psr7Request = new Request(
        $request['http_method'],
        (new Uri($request['uri']))
            ->withScheme($request['scheme'])
            ->withHost($request['headers']['host'][0]),
        $request['headers'],
        $request['body']
    );

    // Sign the PSR-7 request with credentials from the environment
    $signedRequest = $signer->signRequest(
        $psr7Request,
        call_user_func($credentialProvider)->wait()
    );

    // Send the signed request to Amazon ES
    /** @var ResponseInterface $response */
    $response = $psr7Handler($signedRequest)->wait();




    // Convert the PSR-7 response to a RingPHP response
    return new CompletedFutureArray([
        'status' => $response->getStatusCode(),
        'headers' => $response->getHeaders(),
        'body' => $response->getBody()->detach(),
        'transfer_stats' => ['total_time' => 0],
        'effective_url' => (string) $psr7Request->getUri(),
    ]);
};

// Use the \Elasticsearch\ClientBuilder class to inject the handler into a
// new Elasticsearch-PHP client:
$client = ClientBuilder::create()
    ->setHandler($handler)
    ->setHosts(['https://xx.eu-west-1.es.amazonaws.com:443'])
    ->build();

@cjyclaire
Copy link
Contributor

@Skiddle As it is an uncaught exception, I don't think there is any recent changes in php SDK relates to elastic search, did you check whether there is any update in elastic search SDK? Is there any other changes made today could cause this trouble?

@bensebborn
Copy link
Author

I'm not aware of anything. I just did an upgrade to check if anything changed, from 3.17.2 => 3.17.3

Same issue though. I just caught the exception and the message is:

The promise was rejected

Catchable fatal error: Argument 1 passed to GuzzleHttp\Ring\Core::proxy() must implement interface GuzzleHttp\Ring\Future\FutureArrayInterface, null given, called in /home/vhosts/x.com/vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php on line 283 and defined in /home/vhosts/x.com/vendor/guzzlehttp/ringphp/src/Core.php on line 335

@jeskew
Copy link
Contributor

jeskew commented Mar 31, 2016

The example in the docs is intended as more of a starting point than a complete implementation, as you would need to implement some form of error handling for a full solution. Since Amazon Elasticsearch Service launched and that example was written, more Elasticsearch tooling has added support for AWS Authentication. There's official support in Elastica >= 3.1.1, and a plugin for Elasticsearch-PHP that decorates the standard handler can be found here.

@jeskew jeskew closed this as completed in 9866db9 Apr 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants