Skip to content

Add a query timeout for silently dead sockets #9

Open

Description

@okomarov

A query on a socket that died silently (a dropped NAT entry, a frozen serverless instance, a half-open TCP connection) waits until TCP gives up, which can take minutes. The server's statement_timeout cannot help, because nothing reaches the server. Keep-alive does not cover data already in flight. Upstream reports: porsager#1089, porsager#513, porsager#394.

Proposal

  • A query_timeout option in seconds, off by default, plus a per-query .timeout(seconds).
  • At expiry, send a CancelRequest. On a live socket the query rejects with 57014 and the connection keeps working.
  • If nothing comes back within a short grace period, destroy the connection and reject with a new QUERY_TIMEOUT code. The socket is presumed dead.

In the phase table this is a queryTimeout event in Ready and Draining (send the cancel and arm the grace timer) and a queryTimeoutGrace event that closes the connection. Initializing needs an explicit decision on whether internal startup queries are covered. No new phase is needed.

Open questions

  • Option names, in seconds like the existing options.
  • Grace period length, and whether it is configurable.
  • Whether the timeout covers queued time or only time on the wire.

Tests

  • Fake server blackhole mode: the socket stays open and nothing is answered or closed.
  • Real PostgreSQL in Docker: kill -STOP the backend process for a genuinely silent server, and check the query fails within bounds.

Activity

  1. added
    enhancement
    on Oct 9, 2026
  2. moved this to Next in Roadmapon Oct 15, 2026
  3. added
    area: timeouts
    upstream
    on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: timeoutsenhancementupstream

    Type

    No type

    Projects

    • Status
      Next

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions