Skip to content

Commit

Permalink
Use monotonically increasing time for timeout - fixes #316
Browse files Browse the repository at this point in the history
  • Loading branch information
porsager committed Apr 15, 2022
1 parent 822fb21 commit 04644c0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
}

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

function connected() {
Expand Down Expand Up @@ -446,7 +446,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
return reconnect()

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

0 comments on commit 04644c0

Please sign in to comment.