Skip to content

Commit c343302

Browse files
[Backport 7.x] Fix 1153 (#1161)
1 parent f9f5d91 commit c343302

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/pool/ConnectionPool.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,17 @@ class ConnectionPool extends BaseConnectionPool {
6060
const { id } = connection
6161
debug(`Marking as 'dead' connection '${id}'`)
6262
if (this.dead.indexOf(id) === -1) {
63-
this.dead.push(id)
63+
// It might happen that `markDead` is called jsut after
64+
// a pool update, and in such case we will add to the dead
65+
// list a node that no longer exist. The following check verify
66+
// that the connection is still part of the pool before
67+
// marking it as dead.
68+
for (var i = 0; i < this.size; i++) {
69+
if (this.connections[i].id === id) {
70+
this.dead.push(id)
71+
break
72+
}
73+
}
6474
}
6575
connection.status = Connection.statuses.DEAD
6676
connection.deadCount++

test/unit/connection-pool.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ test('API', t => {
7474
}, 10)
7575
})
7676

77+
t.test('markDead should ignore connections that no longer exists', t => {
78+
const pool = new ConnectionPool({ Connection, sniffEnabled: true })
79+
pool.addConnection('http://localhost:9200/')
80+
pool.markDead({ id: 'foo-bar' })
81+
t.deepEqual(pool.dead, [])
82+
t.end()
83+
})
84+
7785
t.test('markAlive', t => {
7886
const pool = new ConnectionPool({ Connection, sniffEnabled: true })
7987
const href = 'http://localhost:9200/'

0 commit comments

Comments
 (0)