elastic / elasticsearch-php

Official PHP client for Elasticsearch.
https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html
MIT License
35 stars 970 forks source link

sniffConnectionPoll may have endless connection error in a long script #1061

Closed lawlielt closed 7 months ago

lawlielt commented 4 years ago

Summary of problem or feature request

a long script may have endless connection error in sniffConnecitonPoll state.

Code snippet of problem

my code is here. when the script run a while when all the server state is alive., the shut down the one of the hosts. then the script will always print ""cURL error 28: Connection timed out after xxxx milliseconds"

$client = Comm_Composer_Elasticsearch::getInstance(
    array(
        "192.168.124.101:9200",
        "192.168.124.102:9200",
        "192.168.124.103:9200",
    ),
    array(
        "connection_pool" => Comm_Composer_Elasticsearch::CONNECTION_POOL_SNIFF,
    )
);
do {
    try {
        $client->health();
    } catch (Throwable $e) {
        var_dump($e->getMessage());
    }
    sleep(5);
} while (true);

the problem is when the server is down, then it clear the sniff wait time. next time it will go in sniffConnection method with the failed the connection. but because the unhandled the exception below in the code, it will failed to update the $this->connections. it will continue try the failed the connection forever.

https://github.com/elastic/elasticsearch-php/blob/8f8cdfbe64cd6365692a5b7b4fea4639ad5b0843/src/Elasticsearch/ConnectionPool/SniffingConnectionPool.php#L120

System details

PR submitted https://github.com/elastic/elasticsearch-php/pull/1059