Skip to content

fix(rds): connect_timeout on RdsServiceGateway so connects fail fast - #153

Merged
Kydoimos97 merged 1 commit into
releasefrom
fix/rds-connect-timeout
Aug 4, 2026
Merged

fix(rds): connect_timeout on RdsServiceGateway so connects fail fast#153
Kydoimos97 merged 1 commit into
releasefrom
fix/rds-connect-timeout

Conversation

@Kydoimos97

Copy link
Copy Markdown
Contributor

Fixes

  • Connection/pool construction no longer hangs forever on an unreachable or saturated database. RdsServiceGateway built its ThreadedConnectionPool (and the reconnect() pool rebuild and single-connection reconnect) with a bare DSN and no connect_timeout, so libpq waited indefinitely for each connect. A consumer whose worker builds the pool at startup could hang forever with no recovery. This is the library-level root cause behind Datadog BUG-96: a transient prod DB CPU saturation left AiAxis hung on pool construction and boot-looping (HTTP 502) for ~40 minutes.
  • Adds a connect_timeout parameter (default 10s, floored to the libpq minimum of 2s) threaded through all three connection sites. Connects now fail fast so consumers can surface the error and self-heal.

Tests

  • Updated the reconnect assertions to expect connect_timeout, and added coverage for default / custom / floored values on the pool constructor. Full tests/ suite green (159 passed), ruff clean.

Impact

Backward compatible — new optional parameter with a safe default; every existing consumer immediately gains fail-fast connects with no code change. Consumers that want a tighter bound (e.g. AiAxis) can pass a smaller value.

References

  • Datadog case BUG-96. Consumed by: AiAxis bump (forthcoming), ai-pipeline bump (follow-up).

RdsServiceGateway built its ThreadedConnectionPool (and the reconnect() pool
rebuild / single-connection reconnect) with a bare DSN and no connect_timeout,
so an unreachable or saturated database caused connection construction to block
indefinitely — a consumer's startup could hang forever with no recovery path.
This turned a transient prod DB CPU saturation into a multi-minute downstream
outage (AiAxis 502 boot loop; Datadog BUG-96).

Add a connect_timeout parameter (default 10s, floored to the libpq minimum of
2s) threaded through every connection site: the pool constructor, the
reconnect() pool rebuild, and the single-connection reconnect. Connections now
fail fast instead of hanging, letting consumers surface the error and recover.
@Kydoimos97
Kydoimos97 requested review from a team and Wrench-Review-Bot August 4, 2026 07:38
@Wrench-Review-Bot

Wrench-Review-Bot commented Aug 4, 2026

Copy link
Copy Markdown

PR Review — APPROVE

Adds connect_timeout (default 10 s, floored to libpq minimum 2 s) to RdsServiceGateway and threads it through the three psycopg2 connection sites the class owns: pool construction, pool rebuild in reconnect(), and single-connection rebuild in reconnect(). Targeted, backward-compatible fix for BUG-96.

Nits

  • Nit: WrenchCL/Connect/AwsClientHub.py:179 — The initial single-connection path (non-multithreaded __init__) goes through AwsClientHub._rds_handle_configurationpsycopg2.connect(host=..., port=..., ...) with no connect_timeout. A saturated DB would still hang the first connect in non-multithreaded mode. This is pre-existing ambient debt in AwsClientHub, not introduced here; the pool / reconnect paths (the BUG-96 scenario) are correctly fixed. Worth a follow-up PR on AwsClientHub._rds_handle_configuration.
  • Nit: WrenchCL/Connect/RdsServiceGateway.py:39 — type annotation is int but the assignment max(2, int(connect_timeout)) silently accepts floats. Union[int, float] would be more accurate, or add a # type: ignore if the narrower hint is intentional.

Context

Diff: 2 files, +55/−5 · Prior reviews: none · Related: Datadog BUG-96; consumer bump PRs forthcoming in AiAxis and ai-pipeline per PR body

— Claude

@Wrench-Review-Bot Wrench-Review-Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

PR Review — APPROVE

Adds connect_timeout (default 10 s, floored to libpq minimum 2 s) to RdsServiceGateway and threads it through the three psycopg2 connection sites the class owns: pool construction, pool rebuild in reconnect(), and single-connection rebuild in reconnect(). Targeted, backward-compatible fix for BUG-96.

Nits

  • Nit: WrenchCL/Connect/AwsClientHub.py:179 — The initial single-connection path (non-multithreaded __init__) goes through AwsClientHub._rds_handle_configurationpsycopg2.connect(host=..., port=..., ...) with no connect_timeout. A saturated DB would still hang the first connect in non-multithreaded mode. This is pre-existing ambient debt in AwsClientHub, not introduced here; the pool / reconnect paths (the BUG-96 scenario) are correctly fixed. Worth a follow-up PR on AwsClientHub._rds_handle_configuration.
  • Nit: WrenchCL/Connect/RdsServiceGateway.py:39 — type annotation is int but the assignment max(2, int(connect_timeout)) silently accepts floats. Union[int, float] would be more accurate, or add a # type: ignore if the narrower hint is intentional.

Context

Diff: 2 files, +55/−5 · Prior reviews: none · Related: Datadog BUG-96; consumer bump PRs forthcoming in AiAxis and ai-pipeline per PR body

— Claude

@Wrench-Review-Bot

Copy link
Copy Markdown

PR Review complete — APPROVED. Full review ↗

@Wrench-Review-Bot Wrench-Review-Bot added lifecycle: 4-ready [4] Approved and ready to merge type: bug Something is broken version: patch Bug fix or small patch — flows first labels Aug 4, 2026
@Kydoimos97
Kydoimos97 merged commit 488c39c into release Aug 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lifecycle: 4-ready [4] Approved and ready to merge type: bug Something is broken version: patch Bug fix or small patch — flows first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants