Fix resurrect timeout formula (#833)

* Fixes #827

* Updated test
This commit is contained in:
Tomas Della Vedova
2019-04-29 09:18:38 +02:00
committed by GitHub
parent 8e8b7fbdee
commit 9320ef939d
2 changed files with 8 additions and 18 deletions

View File

@ -34,11 +34,7 @@ class ConnectionPool {
this._ssl = opts.ssl
this._agent = opts.agent
// the resurrect timeout is 60s
// we multiply it by 2 because the resurrect formula is
// `Math.pow(resurrectTimeout * 2, deadCount -1)`
// and we don't need to multiply by 2
// the resurrectTimeout every time
this.resurrectTimeout = 1000 * 60 * 2
this.resurrectTimeout = 1000 * 60
// number of consecutive failures after which
// the timeout doesn't increase
this.resurrectTimeoutCutoff = 5
@ -94,15 +90,9 @@ class ConnectionPool {
connection.status = Connection.statuses.DEAD
connection.deadCount++
// resurrectTimeout formula:
// `Math.pow(resurrectTimeout * 2, deadCount -1)`
// we don't need to multiply the resurrectTimeout by 2
// every time, it is cached during the initialization
connection.resurrectTimeout = Date.now() + Math.pow(
this.resurrectTimeout,
Math.min(
connection.deadCount - 1,
this.resurrectTimeoutCutoff
)
// `resurrectTimeout * 2 ** min(deadCount - 1, resurrectTimeoutCutoff)`
connection.resurrectTimeout = Date.now() + this.resurrectTimeout * Math.pow(
2, Math.min(connection.deadCount - 1, this.resurrectTimeoutCutoff)
)
// sort the dead list in ascending order

View File

@ -74,7 +74,7 @@ test('Should execute the recurrect API with the ping strategy', t => {
})
q.add((q, done) => {
clock.tick(10)
clock.tick(1000 * 61)
client.info((err, result) => {
t.error(err)
done()
@ -133,7 +133,7 @@ test('Resurrect a node and handle 502/3/4 status code', t => {
})
q.add((q, done) => {
clock.tick(10)
clock.tick(1000 * 61)
client.info((err, result) => {
t.error(err)
done()
@ -141,7 +141,7 @@ test('Resurrect a node and handle 502/3/4 status code', t => {
})
q.add((q, done) => {
clock.tick(150000)
clock.tick(1000 * 10 * 60)
client.info((err, result) => {
t.error(err)
done()
@ -194,7 +194,7 @@ test('Should execute the recurrect API with the optimistic strategy', t => {
})
q.add((q, done) => {
clock.tick(10)
clock.tick(1000 * 61)
client.info((err, result) => {
t.error(err)
done()