fix(storage): stop reader lease release deadlocks from failing MySQL runs - #268
Merged
Merged
Conversation
Releasing a Storage Reader Lease raced the cascade delete of its storage location, which locks the same rows in the opposite order. MySQL picked the release as the deadlock victim, and since it was fire-and-forget the error surfaced as an unhandled rejection that failed CI. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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
The
gcs, mysqlunit tests failed (run) with every test passing. The cause was an unhandledER_LOCK_DEADLOCKrejection. When a download stream ends, we release its Storage Reader Lease without awaiting it. If the storage location gets deleted at the same time, its cascade delete locks the same lease rows in the opposite order. MySQL then kills the release, and nothing catches the error.The release now retries on lock conflicts with the existing
retryOnLockConflicthelper. If it still fails, we log a warning instead of leaving an unhandled rejection. That's safe because an unreleased lease expires anyway.📦 Changes
releaseReaderLeaseretries on deadlocks and lock wait timeouts✅ Verification
devwith MySQL: 5-6ER_LOCK_DEADLOCKs per run, always on the release. With this fix: 0.VITEST_DB_DRIVER=mysql VITEST_STORAGE_DRIVER=gcs vitest run tests/cleanup-lifecycle.test.ts tests/storage-lifecycle.test.ts: 12 passed, 1 skippedtsc --noEmit,eslint,prettier --checkon changed files: cleanretryOnLockConflictalready has unit tests.🤖 Generated with Claude Code