Skip to content

Commit ee36f7b

Browse files
committed
Fix resurrect timeout formula (#833)
* Fixes #827 * Updated test
1 parent 8a85738 commit ee36f7b

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

lib/ConnectionPool.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ class ConnectionPool {
3434
this._ssl = opts.ssl
3535
this._agent = opts.agent
3636
// the resurrect timeout is 60s
37-
// we multiply it by 2 because the resurrect formula is
38-
// `Math.pow(resurrectTimeout * 2, deadCount -1)`
39-
// and we don't need to multiply by 2
40-
// the resurrectTimeout every time
41-
this.resurrectTimeout = 1000 * 60 * 2
37+
this.resurrectTimeout = 1000 * 60
4238
// number of consecutive failures after which
4339
// the timeout doesn't increase
4440
this.resurrectTimeoutCutoff = 5
@@ -94,15 +90,9 @@ class ConnectionPool {
9490
connection.status = Connection.statuses.DEAD
9591
connection.deadCount++
9692
// resurrectTimeout formula:
97-
// `Math.pow(resurrectTimeout * 2, deadCount -1)`
98-
// we don't need to multiply the resurrectTimeout by 2
99-
// every time, it is cached during the initialization
100-
connection.resurrectTimeout = Date.now() + Math.pow(
101-
this.resurrectTimeout,
102-
Math.min(
103-
connection.deadCount - 1,
104-
this.resurrectTimeoutCutoff
105-
)
93+
// `resurrectTimeout * 2 ** min(deadCount - 1, resurrectTimeoutCutoff)`
94+
connection.resurrectTimeout = Date.now() + this.resurrectTimeout * Math.pow(
95+
2, Math.min(connection.deadCount - 1, this.resurrectTimeoutCutoff)
10696
)
10797

10898
// sort the dead list in ascending order

test/behavior/resurrect.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ test('Should execute the recurrect API with the ping strategy', t => {
7474
})
7575

7676
q.add((q, done) => {
77-
clock.tick(10)
77+
clock.tick(1000 * 61)
7878
client.info((err, result) => {
7979
t.error(err)
8080
done()
@@ -133,15 +133,15 @@ test('Resurrect a node and handle 502/3/4 status code', t => {
133133
})
134134

135135
q.add((q, done) => {
136-
clock.tick(10)
136+
clock.tick(1000 * 61)
137137
client.info((err, result) => {
138138
t.error(err)
139139
done()
140140
})
141141
})
142142

143143
q.add((q, done) => {
144-
clock.tick(150000)
144+
clock.tick(1000 * 10 * 60)
145145
client.info((err, result) => {
146146
t.error(err)
147147
done()
@@ -194,7 +194,7 @@ test('Should execute the recurrect API with the optimistic strategy', t => {
194194
})
195195

196196
q.add((q, done) => {
197-
clock.tick(10)
197+
clock.tick(1000 * 61)
198198
client.info((err, result) => {
199199
t.error(err)
200200
done()

0 commit comments

Comments
 (0)