Occasional `TimeoutNegativeWarning: -81612681.54468305 is a negative number.`
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.
same issue
DId u know is there any bad thing which happends because of it?
This happened in Bun too
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.
I use Bun and got the same issue
But after many times it looks like everything works fine
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))
Another package "cron" has a similar issue. Link is here: https://github.com/kelektiv/node-cron/issues/1000
@porsager, when can we expect the fix to be released?