Skip to content

fix(mysql): forceClose and disconnect during connect end the attempt (#1313) - #1326

Merged
ZhuchkaTriplesix merged 1 commit into
devfrom
fix/1313-mysql-forceclose-connect
Oct 10, 2026
Merged

ZhuchkaTriplesix merged 1 commit into
devfrom
fix/1313-mysql-forceclose-connect

Conversation

@ZhuchkaTriplesix

Copy link
Copy Markdown
Member

Closes #1313

Problem (mysql_connection.dart)

  • forceClose did if (c == null) return; before releasing the SSH handle. Called while connect() was between opening the tunnel and creating the driver connection, it left the tunnel's reference counted for good.
  • The attempt it overtook went on and set _isConnected = true: the interrupted session came back connected. PostgreSQL's forceClose handles both.
  • _connecting still held the overtaken attempt, so a connect() after a forceClose joined it.

Fix

  • _generation, bumped by disconnect and forceClose (which also clear _connecting). _connectOnce records it, checks it after the tunnel opens and after the handshake; when it changed, it closes the driver connection and releases the tunnel it opened (the fields may belong to a newer attempt), and fails with StateError('The connection was closed while it was being opened').
  • forceClose no longer returns early: the tunnel is released whether or not there was a connection.

Tests (mysql_connect_cancel_test.dart, fake SSH server with a connect delay): forceClose and disconnect during the tunnel's opening end the attempt within the tunnel's time (not after the 6 s handshake wait), leave it not connected and the tunnel session count at zero; a connect after a forceClose is a new attempt.

…1313)

forceClose returned before releasing the SSH tunnel when there was no
connection object yet, and the attempt it overtook finished as a
connected session. An attempt now notes the generation it started in;
when disconnect or forceClose bumped it, the attempt closes what it
opened, releases its tunnel and fails, and a connect after a forceClose
starts a new attempt instead of joining the overtaken one.
@github-actions github-actions Bot added bug Something isn't working stability Theme parser epic label: stability mysql MySQL database driver and workspace connections Database connections, URI parsing, pools P3 Low priority / Polish & Enhancements labels Oct 10, 2026
@ZhuchkaTriplesix
ZhuchkaTriplesix merged commit 0d0dbd9 into dev Oct 10, 2026
15 checks passed
@ZhuchkaTriplesix
ZhuchkaTriplesix deleted the fix/1313-mysql-forceclose-connect branch October 11, 2026 15:02
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 mysql MySQL database driver and workspace P3 Low priority / Polish & Enhancements stability Theme parser epic label: stability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant