Skip to content

fix(db): every PostgreSQL call waits its turn; a wait for the connection has its own limit and message (#1216) - #1260

Merged
ZhuchkaTriplesix merged 2 commits into
devfrom
issue/1216-session-timeouts
Oct 10, 2026
Merged

ZhuchkaTriplesix merged 2 commits into
devfrom
issue/1216-session-timeouts

Conversation

@ZhuchkaTriplesix

Copy link
Copy Markdown
Member

Summary

Finishes #1216 after #1222, which queued execute and kept the session on a 57014 cancel.

  • Metadata and stats queries go through the queue. PostgresConnection sent ~30 calls straight to the driver (tables, columns, PKs, stats, version(), the transaction probe…), past our statement queue. The driver starts their default 30 s timeout while they wait for the connection, so one queued behind a long statement could still cancel it. They now run through _queued.
  • StatementQueue (core/database/statement_queue.dart) replaces the two copies of the queue in the PostgreSQL and MySQL wrappers. A statement that waits longer than waitLimit (2 min) fails with StatementWaitTimeoutException and never runs; the statement it waited for is not touched.
  • Messages. The SQL editor shows Query timed out after 30 s for a statement that ran too long and Waited 120 s for the connection: another statement is still running on it. for one that never got the session. The error mapper (and through it MCP) maps the wait to its own message and hint. A server cancel without a duration keeps its reason (Query timed out: canceling statement due to user request).

Acceptance tests (test/core/database/statement_queue_test.dart):

  • after a 57014 cancel, the next statement runs on the same session;
  • a statement longer than the next one's timeout is not cancelled, and the next timeout reaches the driver only when that statement starts;
  • a bare TimeoutException closes only its own session;
  • a MySQL query waiting 11 s (fake time) behind another keeps the session;
  • the wait limit fails only the waiting statement, which never runs.

Not in this PR: server-side statement_timeout / max_execution_time for the editor and browse sessions (MCP already has its own since #1217), and SQLite still closes its session on a timeout.

Closes #1216

Test plan

  • CI: analysis and all test sections pass (no local runs, per team rule)

…mit and error (#1216)

The metadata and stats queries of PostgresConnection went to the driver
directly, past our statement queue. The driver starts their default 30 s
timeout while they wait for the connection, so one queued behind a long
statement could still cancel it. They now run in the queue too.

StatementQueue replaces the two copies of the queue in the PostgreSQL and
MySQL wrappers. A statement that waits longer than its limit (2 min) fails
with StatementWaitTimeoutException ('Waited 120 s for the connection') and
never runs; the statement it waited for is not touched.
…acceptance tests

The SQL editor shows 'Query timed out after 30 s' for a statement that ran
too long and 'Waited 120 s for the connection' for one that never got the
session; the error mapper (and through it MCP) maps the wait to its own
message and hint.

Tests: after a 57014 cancel the next statement runs on the session; a
statement longer than the next one's timeout is not cancelled and the next
timeout reaches the driver only when the next statement starts; a bare
TimeoutException closes only its own session; a MySQL query waiting 11 s
behind another keeps the session; the wait limit fails only the waiting
statement.
@github-actions github-actions Bot added bug Something isn't working stability Theme parser epic label: stability core Core library logic and services connections Database connections, URI parsing, pools P1 High priority / Core capability labels Oct 10, 2026
@ZhuchkaTriplesix
ZhuchkaTriplesix merged commit ed2c2f9 into dev Oct 10, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working connections Database connections, URI parsing, pools core Core library logic and services P1 High priority / Core capability stability Theme parser epic label: stability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant