Skip to content

fix(pg): apply statement_timeout, lock_timeout and idle_in_transaction_session_timeout with the native client - #3877

Open
cesco69 wants to merge 1 commit into
brianc:masterfrom
cesco69:fix/native-timeouts
Open

cesco69 wants to merge 1 commit into
brianc:masterfrom
cesco69:fix/native-timeouts

Conversation

@cesco69

@cesco69 cesco69 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

With the native client, statement_timeout, lock_timeout and idle_in_transaction_session_timeout are silently ignored:

const pool = new pg.native.Pool({ statement_timeout: 30000 })
await pool.query('SHOW statement_timeout') // 0

The JavaScript client sends them as startup parameters, but the native client connects with a libpq connection string, and getLibpqConnectionString leaves them out.

Change

libpq has no connection keyword for these settings, so they are appended to options as -c name=value. They are placed after the user's own options, so the dedicated setting wins over the same setting inside options. That is what already happens with the JavaScript client, where the server applies the startup parameters after options.

Values go through parseInt, as in Client#getStartupConf, so numbers, floats and numeric strings behave the same with both clients.

Tests

  • Three unit tests on the libpq connection string: timeouts only, timeouts together with options, and options only.
  • The existing statement_timeout and idle_in_transaction_session_timeout integration tests were skipped with the native client ("not supported with the native client"). They now run with both.

Locally I ran the new unit tests and those two integration files, with the native and the JavaScript client, against PostgreSQL. I did not run the whole suite.

Notes

  • One behaviour change for native users: a timeout that is already in their config and has been ignored so far starts to apply.
  • As discussed in native driver ignores statement_timeout #2103, PgBouncer rejects options as a startup parameter unless it is listed in ignore_startup_parameters. It already rejects the same timeouts when they come from the JavaScript client, so the two clients now behave alike there too.

Fixes #2103. Supersedes #2323, which has conflicts with master and predates lock_timeout.

🤖 Generated with Claude Code

…n_session_timeout with the native client

The native client connects with a libpq connection string, and
getLibpqConnectionString did not include these three settings, so they
were silently ignored: `SHOW statement_timeout` returned 0 whatever the
config said.

libpq has no connection keyword for them, so they are appended to
`options` as `-c name=value`. They go after the user's own options so
that they take precedence, as they already do with the JavaScript
client, where they are sent as startup parameters.

The statement_timeout and idle_in_transaction_session_timeout
integration tests now run with the native client too.

Fixes brianc#2103

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

native driver ignores statement_timeout

2 participants