Repository navigation
fix(pg, pg-pool): clamp timer delays to what setTimeout supports - #3817
Open
OsamaAnsar wants to merge 1 commit into
Open
OsamaAnsar wants to merge 1 commit into
OsamaAnsar wants to merge 1 commit into
Conversation
setTimeout() treats a delay above 2^31-1 ms (about 24.8 days) as 1 ms, so a large maxLifetimeSeconds, idleTimeoutMillis, connectionTimeoutMillis or query_timeout made its timer fire almost immediately. Clamp the delay at each call site.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
setTimeout()treats a delay above 2^31-1 ms (about 24.8 days) as 1 ms, so a largemaxLifetimeSeconds,idleTimeoutMillis,connectionTimeoutMillisorquery_timeoutmade its timer fire almost immediately. This clamps the delay at eachsetTimeoutcall (pg-pool x4,Clientx2, and the native client'squery_timeout). Values that were already in range are unchanged.Before/after, real
pg+pg-poolfrom this checkout against PGlite, 6 sequentialselect 1on a pool of 1:maxLifetimeSeconds: 2592000idleTimeoutMillis: 3e9idleTimeoutMillis: Infinityquery_timeout: 2**31,pg_sleep(0.3)Query read timeoutafter 302 msconnectionTimeoutMillis: 2**31(client)timeout expiredafter 2 msTests:
packages/pg-pool/test/timer-overflow.js(mock client, no database) and four cases inpackages/pg/test/unit/client/query-timeout-tests.js(record the delay passed tosetTimeout). With only the source change reverted, all 5 pool tests fail and the newpgunit tests fail; with the fix they pass. ESLint/prettier clean on the touched packages.Not run: the pg-pool and pg integration suites (need a live Postgres), and the native client change (no
pg-nativehere). Tested on Node 24 only; the change isMath.minon a number, so I don't expect it to differ on Bun, Deno or Workers, but I haven't run it there.Open PRs #3721/#3711 (pg-pool
connectionTimeoutMillis) and #3815 (query_timeoutinclient.js) edit lines next to these, so expect a small conflict with whichever lands second.