Skip to content

Commit f91465d

Browse files
committed
Do not schedule connection pool checks on 4xx level errors
Closes #636
1 parent 3e01b9e commit f91465d

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/Elasticsearch/Transport.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,11 @@ function ($response) {
114114
},
115115
//onFailure
116116
function ($response) {
117-
//some kind of real faiure here, like a timeout
118-
$this->connectionPool->scheduleCheck();
119-
// log stuff
117+
// Ignore 400 level errors, as that means the server responded just fine
118+
if (!(isset($response['code']) && $response['code'] >=400 && $response['code'] < 500)) {
119+
// Otherwise schedule a check
120+
$this->connectionPool->scheduleCheck();
121+
}
120122
});
121123

122124
return $future;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/**
4+
* Class StaticConnectionPoolIntegrationTest
5+
*
6+
* @category Tests
7+
* @package Elasticsearch
8+
* @subpackage Tests/StaticConnectionPoolTest
9+
* @author Zachary Tong <[email protected]>
10+
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
11+
* @link http://elasticsearch.org
12+
*/
13+
class StaticConnectionPoolIntegrationTest extends \PHPUnit_Framework_TestCase
14+
{
15+
// Issue #636
16+
public function test404Liveness() {
17+
$client = \Elasticsearch\ClientBuilder::create()
18+
->setHosts([$_SERVER['ES_TEST_HOST']])
19+
->setConnectionPool(\Elasticsearch\ConnectionPool\StaticConnectionPool::class)
20+
->build();
21+
22+
$connection = $client->transport->getConnection();
23+
24+
// Ensure connection is dead
25+
$connection->markDead();
26+
27+
// The index doesn't exist, but the server is up so this will return a 404
28+
$this->assertFalse($client->indices()->exists(['index' => 'not_existing_index']));
29+
30+
// But the node should be marked as alive since the server responded
31+
$this->assertTrue($connection->isAlive());
32+
}
33+
}

0 commit comments

Comments
 (0)