Repository navigation
Reconnect to the database the session last used - #266
Open
quinnj-bot[bot] wants to merge 2 commits into
Open
quinnj-bot[bot] wants to merge 2 commits into
quinnj-bot[bot] wants to merge 2 commits into
Conversation
The fake peer records the database of each handshake: after USE, a dropped connection must come back into that database, and after the current database is dropped, into none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The server reports USE (and dropping the current database) in a SESSION_TRACK_SCHEMA block. The driver parsed the block but reconnected with the database from connect time, so after a reconnect unqualified queries ran against a different database. libmysqlclient and 1.x follow the tracked schema. Protocol.Session keeps the schema (requested at authentication, then each tracked change in an OK packet), and ensure_live! reconnects with it; connect(opts; db) sets CLIENT_CONNECT_WITH_DB to match. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
With
reconnect=true, a connection that changed its database withUSEsilently goes back tothe database it was opened with after a reconnect. Every unqualified query after the reconnect
then reads and writes the wrong tables, with no error. MySQL.jl 1.x (libmariadb) and
libmysqlclient reconnect to the database the session last used.
Repro against MySQL 8.4, MariaDB 11.4 and MySQL 8.0 (2.4.0):
What changed
The server already reports every change of the default database (
USE, or dropping thecurrent database) in a
SESSION_TRACK_SCHEMAblock of its OK packet. The driver parsed thatblock (
Protocol.schema_change) but never used it.Protocol.Sessionkeepsschema: the database requested at authentication, then eachSESSION_TRACK_SCHEMAchange seen in an OK packet (command OK, result-set terminator, auth OK).ensure_live!reconnects with the dead session'sschema.connect(opts; db)takes thedatabase to open and sets
CLIENT_CONNECT_WITH_DBto match, so a connection opened withouta database can come back into the one a
USEselected, and one whose database was droppedcomes back with none.
reconnectrow of the options table.Verification
reconnect restores the database the session last reported(fake peerthat records the database in each handshake). On main it fails: the server sees
["<none>", "<none>", "<none>"]instead of["<none>", "other", "<none>"]. On this branch it passes.with and without a database: main reconnects into the original database; this branch
reconnects into the
USEd one, and afterDROP DATABASEof the current one into none.Pkg.test()on Julia 1.12.6, serverless lanes plus the--trim=safeworkload(
MYSQL_INTEGRATION=0 MYSQL_PERF_GATES=0):MySQL | 1917 1917, trim compile clean. Thesame suite on main with only the new test: 1909 pass, 1 fail (the new test). The Docker
integration lanes run in CI.
Reviewed by re-reading the diff for: every OK-packet parse site (command OK, result
terminator, auth OK; EOF terminators carry no session state); a failed reconnect keeps the
dead handle, so the retry uses the same database;
init_commandand aUSEinsidemulti-statement or
CALLresults go through the same OK parsing; session tracking off(
session_track_schema=OFF) leaves the original database, as in libmysqlclient.🤖 Generated with Claude Code