elasticsearch-php icon indicating copy to clipboard operation
elasticsearch-php copied to clipboard

sniffConnectionPoll may have endless connection error in a long script

Open lawlielt opened this issue 5 years ago • 0 comments

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

  • Operating System macOS 10.15.6 (19G2021)
  • PHP Version PHP 7.3.11
  • ES-PHP client version v7.4
  • Elasticsearch version 7.6.2

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

lawlielt avatar Sep 11 '20 03:09 lawlielt