Skip to content

fix(db): statements run one at a time per session; a server cancel keeps the session (#1216) - #1222

Merged
ZhuchkaTriplesix merged 2 commits into
devfrom
fix/1216-timeouts-shared-session
Oct 9, 2026
Merged

ZhuchkaTriplesix merged 2 commits into
devfrom
fix/1216-timeouts-shared-session

Conversation

@ZhuchkaTriplesix

@ZhuchkaTriplesix ZhuchkaTriplesix commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Refs #1216

What was wrong

  • Every TimeoutException closed the pooled session, including a server-side cancel (SQLSTATE 57014). The driver reports that cancel as a PgException, and the session stays healthy; closing it dropped the tree, the table tabs, the Relations view and MCP together.
  • The postgres driver starts a statement's timeout before the statement gets its turn behind another one on the same session. A statement that waited behind a slow one could cancel the slow one through the server.
  • The MySQL client waits for the previous statement by polling and gives up after 10 s, which closed the session for every caller.

Changes

  • PostgreSQL: a PgException from a statement keeps the session; a bare TimeoutException closes it, since the protocol may be out of step.
  • PostgreSQL and MySQL: statements on one session run one at a time in our own queue. The driver's timer therefore starts when a statement starts, and no statement is cancelled for another one.
  • executeWithTimeout passes its timeout to the statement instead of wrapping the whole call, so time in the queue does not count.
  • Tests: a server cancel keeps the session; a bare timeout closes it; two statements on one session run in order (PostgreSQL and MySQL); a timed-out MySQL statement closes the session. The existing postgres timeout test now drives the real path through a test seam.

Not in this PR

  • A timed-out MySQL statement still closes its session. The client cannot cancel a running statement; KILL QUERY on a second connection would keep the session, and is a follow-up.
  • A waiting statement has no separate "waited too long for the connection" error; it waits in the queue, bounded by the statement's own timeout once it starts.
  • A result read as a stream (iterable: true, MySQL SQL editor) is released from the queue before its rows are read; the client's own wait still applies to the next statement, as before.
  • SQLite is not changed.
  • The sequence and routine views (fix(db): closing a table tab force-closes the read-only session other views are using #1215 follow-up) are not changed.

Not verified locally

Tests were not run locally, per the project rule.

…eps the session (#1216)

PostgreSQL: every timeout, including a server-side cancel (SQLSTATE 57014),
closed the shared session. A cancel arrives as a PgException and leaves the
session healthy; only a bare TimeoutException closes it now. Statements on a
session run one at a time in our own queue: the driver started a statement's
timeout before the statement got its turn, so a statement waiting behind
another one could cancel that one. executeWithTimeout passes its timeout to the
statement, which now starts when the statement does.

MySQL: statements run one at a time in the same way, so the client's 10 s wait
for the previous statement no longer closes the session for every caller. A
timed-out statement still closes its session: the client cannot cancel it.
@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 9, 2026
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

Grid scroll benchmark

metric base PR change
p50 14.34 ms 9.21 ms -35.8%
p90 19.83 ms 22.66 ms +14.3% ⚠️
p99 45.76 ms 46.27 ms +1.1%
stutters 318.00 309.00 -2.8%

Informational only (threshold 5%). Shared CI runners are noisy; re-run before trusting a single result.

@ZhuchkaTriplesix
ZhuchkaTriplesix merged commit e2f5f80 into dev Oct 9, 2026
14 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