fix: explicitly RELEASE_LOCK before closing metadata lock connection#754
Merged
Conversation
This was referenced May 1, 2026
Relying on connection close (COM_QUIT) alone to release GET_LOCK leaves a small window where MySQL has not yet finished tearing down the session. A rapid reacquire on a new connection can see the lock as still held, which manifests as flaky resume tests where m1 closes and m2 immediately tries to acquire the same lock. Calling RELEASE_LOCK on the same session before closing the connection makes release synchronous and removes the race. Fixes block#761. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
DO is a less familiar MySQL statement and may not be handled correctly by all proxies / routing layers. SELECT works everywhere and matches the GET_LOCK call pattern. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
00bba5e to
fe4b3db
Compare
aparajon
approved these changes
May 1, 2026
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.
Summary
Fixes #761:
MetadataLock.Close()was relying on connection close (COM_QUIT) alone to releaseGET_LOCK, which leaves a small window where MySQL has not yet finished tearing down the session. A fresh connection arriving in that window sees the lock as still held by another connection.This PR calls
RELEASE_LOCKon the same session before closing the connection.RELEASE_LOCKis synchronous within the session, so by the timeMetadataLock.Close()returns, MySQL guarantees the named locks are no longer held — eliminating the race.The query uses
SELECT RELEASE_LOCK(?)(rather thanDO RELEASE_LOCK(?)) so it's familiar to readers and handled correctly by routing layers / proxies that may not understandDO.Relationship to #742
#742 (the flaky
TestResumeFromCheckpointStrictTooOldtest) was originally reported with thelock is held by another connectionsymptom, which is exactly the race this PR eliminates. However, after this fix lands, the test still has a separate failure mode — m2 sometimes succeeds at acquiring the lock and reading the checkpoint, but doesn't detect it as too old, so it resumes when it should error. That second mode is unrelated to lock release and will be addressed in a follow-up PR. #742 stays open until that's done.Test plan
TestMetadataLock/TestMetadataLockContextCancel— close-then-reacquire should now be deterministic.🤖 Generated with Claude Code