Skip to content

Commit 04644c0

Browse files
committed
Use monotonically increasing time for timeout - fixes porsager#316
1 parent 822fb21 commit 04644c0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/connection.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
359359
}
360360

361361
function reconnect() {
362-
setTimeout(connect, closedDate ? closedDate + delay - Date.now() : 0)
362+
setTimeout(connect, closedDate ? closedDate + delay - Number(process.hrtime.bigint() / 1000000n) : 0)
363363
}
364364

365365
function connected() {
@@ -446,7 +446,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
446446
return reconnect()
447447

448448
!hadError && (query || sent.length) && error(Errors.connection('CONNECTION_CLOSED', options, socket))
449-
closedDate = Date.now()
449+
closedDate = Number(process.hrtime.bigint() / 1000000n)
450450
hadError && options.shared.retries++
451451
delay = (typeof backoff === 'function' ? backoff(options.shared.retries) : backoff) * 1000
452452
onclose(connection)

0 commit comments

Comments
 (0)