Skip to content

fix(db): one connect attempt per pooled connection, one reconnect per dropped slot (#1214) - #1220

Merged
ZhuchkaTriplesix merged 1 commit into
devfrom
fix/1214-concurrent-connect
Oct 9, 2026
Merged

ZhuchkaTriplesix merged 1 commit into
devfrom
fix/1214-concurrent-connect

Conversation

@ZhuchkaTriplesix

Copy link
Copy Markdown
Member

Refs #1214

What was wrong

  • connect() on a pooled PostgreSQL or MySQL connection was not guarded. Two callers arriving during an attempt each opened a socket and an SSH tunnel; the later assignment won and the earlier ones leaked, and a failing attempt cleared the session the other one had made.
  • Two callers on a dropped pool slot each reconnected and each set the session read-only mode.

Changes

  • connect() shares the attempt in progress: a second caller awaits the same future. The attempt itself is the former body, now _connectOnce. PostgreSQL and MySQL.
  • The PostgreSQL and MySQL pools reconnect a dropped entry through _reconnect, which shares one reconnect and one setSessionReadOnly between concurrent callers.
  • Tests in both pool files: two concurrent acquires on a dropped slot → one extra connect and one session setting, and both leases get the same connection.

Not in this PR

  • A test that two concurrent connect() calls on one connection open one socket and one tunnel. That needs a seam to replace the socket open; the pool tests do not reach it.
  • SQLite is not changed: sqflite reuses one instance per path.
  • A forceClose during an attempt still sets the connection state from the attempt that finishes later. That was already so and is not part of this issue.

Not verified locally

Tests were not run locally, per the project rule.

… dropped slot (#1214)

Two callers that arrived while a pooled connection was connecting each opened a
socket and an SSH tunnel; the later assignment won and the earlier ones leaked,
and a failing attempt cleared the session the other attempt had made. connect()
now shares the attempt in progress (PostgreSQL and MySQL). The pools share one
reconnect for a dropped slot, so the session setting runs once.
@github-actions github-actions Bot added bug Something isn't working stability Theme parser epic label: stability connections Database connections, URI parsing, pools P2 Medium priority / Parity & Refactoring labels Oct 9, 2026
@ZhuchkaTriplesix
ZhuchkaTriplesix merged commit b0dbac6 into dev Oct 9, 2026
14 checks passed
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

Grid scroll benchmark

metric base PR change
p50 13.17 ms 14.15 ms +7.4% ⚠️
p90 19.06 ms 18.25 ms -4.2%
p99 41.97 ms 43.56 ms +3.8%
stutters 327.00 327.00 +0.0%

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

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 P2 Medium priority / Parity & Refactoring stability Theme parser epic label: stability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant