P0: Configure Postgres pool limits + statement_timeout (#165)#182
Open
dkijania wants to merge 1 commit into
Open
P0: Configure Postgres pool limits + statement_timeout (#165)#182dkijania wants to merge 1 commit into
dkijania wants to merge 1 commit into
Conversation
The archive-node Postgres client was created with `postgres(connectionString)` and no pool sizing or timeouts. With the API exposed publicly this is a denial- of-service risk: one expensive query can hold a connection open indefinitely, exhausting the pool and cascading into an outage. Add a small, unit-testable `postgres-options` module that builds the client options from conservative, env-tunable defaults: - PG_MAX_CONNECTIONS (max pooled connections, default 10) - PG_IDLE_TIMEOUT (seconds, default 30) - PG_CONNECT_TIMEOUT (seconds, default 30) - PG_STATEMENT_TIMEOUT(ms server-side query cap, default 30000; 0 disables) Malformed values fall back to defaults rather than throwing, so a stray typo can never silently disable a safety limit. Docs, env example, and env type declarations updated; unit tests cover parsing, fallbacks, and the options shape. Also anchor the `db/` and `data/` .gitignore rules to the repo root (`/db/`, `/data/`). The unanchored `db/` matched `src/db/` anywhere in the tree, which silently ignored the new module file. Closes #165. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QSuak9smCHbp4N17xjjLF6
58c7d49 to
dfcad11
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Part of the production-readiness epic (#163). Closes #165.
The archive-node Postgres client was created with
postgres(connectionString)and no pool sizing or timeouts. Once the API is publicly reachable this is a DoS risk — a single expensive query can hold a connection open indefinitely, exhaust the pool, and cascade into an outage.Changes
src/db/archive-node-adapter/postgres-options.ts— builds thepostgres()options from conservative, env-tunable defaults, isolated so it's unit-testable without a DB.postgres(connectionString, buildPostgresOptions()).PG_MAX_CONNECTIONS10PG_IDLE_TIMEOUT30PG_CONNECT_TIMEOUT30PG_STATEMENT_TIMEOUT300000disablesMalformed values fall back to defaults rather than throwing, so a stray typo can never silently disable a safety limit (e.g.
max→ 0).statement_timeoutis sent as a startup connection parameter, so it applies to every query on every connection.Docs (
getting-started.md),.env.example.compose, andenvionment.d.tsupdated; new unit tests cover parsing, fallbacks, clamping, and the options shape.Testing
npm run build— cleannpm run test:unit— all pass (6 new assertions inpostgres-options.test.ts)npm run lint— cleannpx prettier --debug-check .— exit 0Tests construct their own
postgresclients directly, so the new adapter defaults don't affect the integration/live-network suites.🤖 Generated with Claude Code