Skip to content

Commit

Permalink
[Backport 7.x] Fix 1153 (#1161)
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored May 14, 2020
1 parent f9f5d91 commit c343302
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/pool/ConnectionPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,17 @@ class ConnectionPool extends BaseConnectionPool {
const { id } = connection
debug(`Marking as 'dead' connection '${id}'`)
if (this.dead.indexOf(id) === -1) {
this.dead.push(id)
// It might happen that `markDead` is called jsut after
// a pool update, and in such case we will add to the dead
// list a node that no longer exist. The following check verify
// that the connection is still part of the pool before
// marking it as dead.
for (var i = 0; i < this.size; i++) {
if (this.connections[i].id === id) {
this.dead.push(id)
break
}
}
}
connection.status = Connection.statuses.DEAD
connection.deadCount++
Expand Down
8 changes: 8 additions & 0 deletions test/unit/connection-pool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ test('API', t => {
}, 10)
})

t.test('markDead should ignore connections that no longer exists', t => {
const pool = new ConnectionPool({ Connection, sniffEnabled: true })
pool.addConnection('http://localhost:9200/')
pool.markDead({ id: 'foo-bar' })
t.deepEqual(pool.dead, [])
t.end()
})

t.test('markAlive', t => {
const pool = new ConnectionPool({ Connection, sniffEnabled: true })
const href = 'http://localhost:9200/'
Expand Down

0 comments on commit c343302

Please sign in to comment.