Skip to content

fix(postgres): enforce query timeout on server - #415

Merged
tianzhou merged 1 commit into
bytebase:mainfrom
rabberbock:fix/postgres-server-query-timeout
Sep 2, 2026
Merged

fix(postgres): enforce query timeout on server#415
tianzhou merged 1 commit into
bytebase:mainfrom
rabberbock:fix/postgres-server-query-timeout

Conversation

@rabberbock

Copy link
Copy Markdown
Contributor

Summary

  • map PostgreSQL query_timeout to the server-side statement_timeout
  • retain the node-postgres client timeout with a five-second fallback grace period
  • verify the backend statement disappears from pg_stat_activity and the connection remains reusable

Why

node-postgres query_timeout only stops the client from waiting. The PostgreSQL backend can continue executing the abandoned statement, which is the same failure class reported for MySQL in #384 and fixed in #386.

Using statement_timeout as a connection startup parameter preserves the existing per-source TOML configuration and requires no role-level or database-level setting. The slightly longer client timeout remains a fallback while allowing the server cancellation response to arrive first.

Testing

  • pnpm run test:unit — 989 passed
  • pnpm exec vitest run --project integration src/connectors/__tests__/postgres.integration.test.ts — 52 passed
  • pnpm run build — passed

Copilot AI 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.

🟢 Approval recommended

The implementation addresses backend query leakage and includes focused configuration and integration coverage.

Pull request overview

Adds server-side PostgreSQL query cancellation while retaining a delayed client-side fallback.

Changes:

  • Maps query_timeout to PostgreSQL statement_timeout.
  • Adds unit and integration coverage for cancellation and connection reuse.
File summaries
File Description
src/connectors/postgres/index.ts Configures server and client timeouts.
src/connectors/__tests__/postgres.integration.test.ts Verifies cancellation and connection reuse.
src/connectors/__tests__/dsn-parser.test.ts Verifies timeout configuration values.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@tianzhou tianzhou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Thanks for the contribution.

@tianzhou
tianzhou merged commit c363004 into bytebase:main Sep 2, 2026
2 checks passed
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.

3 participants