Skip to content

Commit

Permalink
Do not schedule connection pool checks on 4xx level errors
Browse files Browse the repository at this point in the history
Closes #636
  • Loading branch information
polyfractal committed Aug 24, 2017
1 parent 71ccfc1 commit fd75e99
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Elasticsearch/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ function ($response) {
},
//onFailure
function ($response) {
//some kind of real faiure here, like a timeout
$this->connectionPool->scheduleCheck();
// log stuff
// Ignore 400 level errors, as that means the server responded just fine
if (!(isset($response['code']) && $response['code'] >=400 && $response['code'] < 500)) {
// Otherwise schedule a check
$this->connectionPool->scheduleCheck();
}
});

return $future;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types = 1);

/**
* Class StaticConnectionPoolIntegrationTest
*
* @category Tests
* @package Elasticsearch
* @subpackage Tests/StaticConnectionPoolTest
* @author Zachary Tong <zachary.tong@elasticsearch.com>
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache2
* @link http://elasticsearch.org
*/
class StaticConnectionPoolIntegrationTest extends \PHPUnit_Framework_TestCase
{
// Issue #636
public function test404Liveness() {
$client = \Elasticsearch\ClientBuilder::create()
->setHosts([$_SERVER['ES_TEST_HOST']])
->setConnectionPool(\Elasticsearch\ConnectionPool\StaticConnectionPool::class)
->build();

$connection = $client->transport->getConnection();

// Ensure connection is dead
$connection->markDead();

// The index doesn't exist, but the server is up so this will return a 404
$this->assertFalse($client->indices()->exists(['index' => 'not_existing_index']));

// But the node should be marked as alive since the server responded
$this->assertTrue($connection->isAlive());
}
}

0 comments on commit fd75e99

Please sign in to comment.