Skip to content

feat: pg query timeout sec - #254

Merged
sophia-bq merged 9 commits into
mainfrom
feat/pg-query-timeout-sec
Dec 2, 2026
Merged

sophia-bq merged 9 commits into
mainfrom
feat/pg-query-timeout-sec

Conversation

@sophia-bq

Copy link
Copy Markdown
Contributor

Summary

feat: pg query timeout sec

Addresses #246

Description

Adds a client-side timeout (0–900s, default 0) for the wrapper's own queries: topology, host role, dialect detection, Blue/Green status, failover ROLLBACK, and the KMS key store. It never applies to application queries.

A database that stops answering, even behind a TCP proxy, now fails with a QueryTimeoutError (a PG::ConnectionBad) instead of blocking indefinitely. The wrapper closes connections it opened itself and leaves the application's connection open.

The topology and Blue/Green monitors default to 5s unless the property is set, and they have their own overrides.

A timeout during dialect detection now propagates instead of being read as "not this dialect", so a wrong dialect is no longer cached for 24 hours.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sophia-bq
sophia-bq requested a review from a team as a code owner November 25, 2026 22:57

@aaron-congo aaron-congo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! A couple of broader points:

  • since this changes behavior fairly broadly, should we add a proxy-based integration test: set pg_query_timeout_sec, cut traffic through the proxy after connecting (connection stays open, server stops answering), then check that (a) the topology monitor recovers instead of hanging, (b) writer failover finishes within failover_timeout_sec, and (c) dialect detection raises instead of caching the wrong dialect. (a) and (b) are essentially the repro from #246. If you'd rather not hold this PR for them, a fast follow-up works too.
  • Remaining unbounded query: HostService#query_id_and_name (instance_identity) still runs without a timeout, should we wrap it? Then again, its only entry point is HostService#identify_host, which isn't called anywhere in lib/

Comment thread spec/unit/failover_plugin_spec.rb Resolved
@sophia-bq
sophia-bq force-pushed the feat/pg-query-timeout-sec branch from 2a1d161 to 7125ea9 Compare November 27, 2026 21:19
@sophia-bq

Copy link
Copy Markdown
Contributor Author

Thanks for working on this! A couple of broader points:

  • since this changes behavior fairly broadly, should we add a proxy-based integration test: set pg_query_timeout_sec, cut traffic through the proxy after connecting (connection stays open, server stops answering), then check that (a) the topology monitor recovers instead of hanging, (b) writer failover finishes within failover_timeout_sec, and (c) dialect detection raises instead of caching the wrong dialect. (a) and (b) are essentially the repro from A half-open topology monitor connection blocks every failover in the process on PostgreSQL #246. If you'd rather not hold this PR for them, a fast follow-up works too.
  • Remaining unbounded query: HostService#query_id_and_name (instance_identity) still runs without a timeout, should we wrap it? Then again, its only entry point is HostService#identify_host, which isn't called anywhere in lib/

Thank you so much for the review! I'll put up a stacked PR shortly to add the integration tests 😄

@sophia-bq
sophia-bq force-pushed the feat/pg-query-timeout-sec branch from 7125ea9 to b4c26b6 Compare December 2, 2026 22:06
@sophia-bq
sophia-bq merged commit 1a58a97 into main Dec 2, 2026
14 checks passed
@sophia-bq
sophia-bq deleted the feat/pg-query-timeout-sec branch December 2, 2026 23:36
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