Skip to content

fix: honour DISABLE_TIMEOUT for idleTimeout and maximumConnectionAge#764

Merged
gajus merged 4 commits intomainfrom
fix/disable-timeout-idle-and-max-age
Mar 12, 2026
Merged

fix: honour DISABLE_TIMEOUT for idleTimeout and maximumConnectionAge#764
gajus merged 4 commits intomainfrom
fix/disable-timeout-idle-and-max-age

Conversation

@gajus
Copy link
Copy Markdown
Owner

@gajus gajus commented Mar 12, 2026

Previously, passing idleTimeout: 'DISABLE_TIMEOUT' was silently ignored
because createPoolConfiguration skipped the assignment when the value was
the sentinel string, leaving the internal number field at its 10_000ms
default. The idle timer then fired as normal.

- Widen PoolConfiguration.idleTimeout to 'DISABLE_TIMEOUT' | number
- Pass the sentinel string through createPoolConfiguration instead of
  skipping it
- Guard setIdleTimer in createConnectionPool with an early return when
  idleTimeout === 'DISABLE_TIMEOUT'
- Update createTestPool helper to accept the widened type
- Add test: idle timeout is disabled when idleTimeout is DISABLE_TIMEOUT

Made-with: Cursor
maximumConnectionAge previously only accepted a number, providing no way
to opt out of age-based connection recycling. This adds 'DISABLE_TIMEOUT'
as an accepted value, consistent with connectionTimeout, statementTimeout,
and idleInTransactionSessionTimeout.

- Widen ClientConfiguration.maximumConnectionAge to
  'DISABLE_TIMEOUT' | number in types.ts
- Widen PoolConfiguration.maximumConnectionAge and pass the sentinel
  string through createPoolConfiguration
- In createConnectionPool, set effectiveMaxAge to Infinity when
  maximumConnectionAge is 'DISABLE_TIMEOUT' so isConnectionTooOld
  always returns false
- Update createTestPool helper to accept the widened type
- Add test: connection is not destroyed when maximumConnectionAge is
  DISABLE_TIMEOUT

Made-with: Cursor
Passing maximumConnectionAge: 0 was silently ignored due to a falsy
check, leaving the 30-minute default in place. This mirrors the existing
idleTimeout=0 handling: warn the caller and clamp to 1ms.

Also adds a createPoolConfiguration unit test file covering all four
cases for both maximumConnectionAge and idleTimeout (0, positive number,
DISABLE_TIMEOUT, undefined/default).

Made-with: Cursor
- Map 'DISABLE_TIMEOUT' to Number.POSITIVE_INFINITY in createPoolConfiguration
  so createConnectionPool works with plain numeric comparisons throughout
- Remove 'DISABLE_TIMEOUT' | number union from createConnectionPool parameter
  types; idleTimeout and maximumConnectionAge are now plain numbers
- Replace string sentinel guard in setIdleTimer with Number.isFinite check
- Simplify effectiveMaxAge computation — Infinity * jitter_factor = Infinity,
  so no special case needed for the disabled state
- Widen DriverConfiguration.maximumConnectionAge to 'DISABLE_TIMEOUT' | number
  in @slonik/driver, consistent with other timeout fields; add temporary cast
  in createPool.ts until the package is republished
- Extract resolveTestTimeout helper in createConnectionPool.test.ts to map
  'DISABLE_TIMEOUT' to Infinity before passing to createConnectionPool
- Add createPoolConfiguration unit tests covering all input cases for both
  idleTimeout and maximumConnectionAge
- Add changeset

Made-with: Cursor
@gajus gajus merged commit c92d1df into main Mar 12, 2026
4 checks passed
@github-actions github-actions bot mentioned this pull request Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants