Skip to content

Comments

Improve behaviour of idle_in_transaction_session_timeout#1155

Open
davibe wants to merge 2 commits intoporsager:masterfrom
davibe:feature/idle_in_transaction_session_timeout
Open

Improve behaviour of idle_in_transaction_session_timeout#1155
davibe wants to merge 2 commits intoporsager:masterfrom
davibe:feature/idle_in_transaction_session_timeout

Conversation

@davibe
Copy link

@davibe davibe commented Jan 29, 2026

Related to #1133

When PostgreSQL kills a connection due to idle_in_transaction_session_timeout, two issues could occur:

  1. Uncatchable crash: nextWrite() attempted to write to a null socket
  2. Silent execution outside transaction!!: If pool had pending queries, the connection would reconnect and subsequent txSql queries could execute on the new connection—outside of the intended transaction context—causing potential data corruption

Changes:

src/connection.js:

  • Set terminated = true in closed() before nulling socket
  • Add null guard in nextWrite() to prevent crash

src/index.js:

  • Track closed state in begin() scope
  • Reject txSql queries immediately if connection was closed, preventing execution after reconnect

This ensures txSql always fails with CONNECTION_CLOSED when the underlying connection is killed, regardless of whether the connection object later reconnects for other pool queries.

@davibe davibe force-pushed the feature/idle_in_transaction_session_timeout branch from 5b7195d to 469e9df Compare January 29, 2026 13:54
@davibe davibe marked this pull request as ready for review January 29, 2026 13:56
@davibe davibe force-pushed the feature/idle_in_transaction_session_timeout branch from 2d36493 to ac5f883 Compare January 30, 2026 09:59
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.

1 participant