postgres icon indicating copy to clipboard operation
postgres copied to clipboard

Occasional `TimeoutNegativeWarning: -81612681.54468305 is a negative number.`

Open peterhirn opened this issue 8 months ago • 5 comments

I'm running a Node.js app in K8s. Occasionally (every other day) I get this warning:

(node:1) TimeoutNegativeWarning: -81612681.54468305 is a negative number.
Timeout duration was set to 1.
    at new Timeout (node:internal/timers:195:17)
    at setTimeout (node:timers:138:19)
    at reconnect (file:///app/server/node_modules/postgres/src/connection.js:353:5)
    at Object.connect (file:///app/server/node_modules/postgres/src/connection.js:113:7)
    at connect (file:///app/server/node_modules/postgres/src/index.js:392:7)
    at Query.handler (file:///app/server/node_modules/postgres/src/index.js:336:14)
    at Query.handle (file:///app/server/node_modules/postgres/src/query.js:140:65)

(with varying negative timeout values)

The stacktrace always points to the reconnect function here https://github.com/porsager/postgres/blob/master/src/connection.js#L353

Unfortunately I don't know how to reproduce this issue. On first glance it looks like it happens directly after the app boots up.

peterhirn avatar Apr 17 '25 09:04 peterhirn

same issue

DId u know is there any bad thing which happends because of it?

This happened in Bun too

kravetsone avatar Apr 23 '25 16:04 kravetsone

We recently update from node 22 to node 24 and from "postgres": "^3.4.5" to "postgres": "^3.4.7" and face the same issue.

sep2 avatar Jun 02 '25 02:06 sep2

I use Bun and got the same issue

But after many times it looks like everything works fine

kravetsone avatar Jun 02 '25 08:06 kravetsone

I don't think there is any negative impact because of this warning, it's just noisy. A simple fix could be

setTimeout(connect, Math.max(closedDate ? closedDate + delay - performance.now() : 0, 0))

peterhirn avatar Jun 02 '25 10:06 peterhirn

Another package "cron" has a similar issue. Link is here: https://github.com/kelektiv/node-cron/issues/1000

jingan-generis avatar Jul 08 '25 14:07 jingan-generis

@porsager, when can we expect the fix to be released?

asadhazara avatar Nov 27 '25 23:11 asadhazara