Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 1153 #1159

Merged
merged 3 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
delvedor marked this conversation as resolved.
Show resolved Hide resolved
}
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()
})

delvedor marked this conversation as resolved.
Show resolved Hide resolved
t.test('markAlive', t => {
const pool = new ConnectionPool({ Connection, sniffEnabled: true })
const href = 'http://localhost:9200/'
Expand Down