fix(pool): discard connection on error 1290 (Aurora read-only failure)#4075
Open
natetarrh wants to merge 3 commits intosidorares:masterfrom
Open
fix(pool): discard connection on error 1290 (Aurora read-only failure)#4075natetarrh wants to merge 3 commits intosidorares:masterfrom
natetarrh wants to merge 3 commits intosidorares:masterfrom
Conversation
During an Aurora MySQL failover, an existing writable connection becomes read-only. Subsequent writes return error 1290 (ER_OPTION_PREVENTS_STATEMENT). Previously, the pool would return this stale read-only connection to the free list, causing all subsequent callers to receive the same broken connection. Now, pool.query() and pool.execute() detect error 1290 and call conn.destroy() instead of conn.release(), forcing the pool to create a fresh connection for the next caller. Adds integration test simulating the failover scenario with a mock server. Amp-Thread-ID: https://ampcode.com/threads/T-019c5422-b69d-7625-bebc-3afe8c55c76f Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019c5422-b69d-7625-bebc-3afe8c55c76f Co-authored-by: Amp <amp@ampcode.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4075 +/- ##
==========================================
+ Coverage 89.87% 89.94% +0.07%
==========================================
Files 86 86
Lines 13624 13651 +27
Branches 1619 1629 +10
==========================================
+ Hits 12244 12279 +35
+ Misses 1380 1372 -8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Amp-Thread-ID: https://ampcode.com/threads/T-019c545b-a6dc-7225-bd61-7d58e0992e50 Co-authored-by: Amp <amp@ampcode.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.
Problem
During an Aurora MySQL failover, an existing writable connection becomes read-only. Subsequent writes return error 1290 (
ER_OPTION_PREVENTS_STATEMENT):The pool returns this stale read-only connection to the free list, so all subsequent callers receive the same broken connection.
Fixes #2050
Prior Art
The Go MySQL driver handles this same scenario by closing the connection and returning
ErrBadConnwhen it encounters errors 1290, 1792, or 1836 during failover. This causes Go'sdatabase/sqlpool to discard the connection and create a new one:https://github.com/go-sql-driver/mysql/blob/76c00e35a8d48f8f70f0e7dffe584692bd3fa612/packets.go#L599-L612
Fix
pool.query()andpool.execute()now detect error 1290 and callconn.destroy()instead ofconn.release(), forcing the pool to create a fresh connection for the next caller.Test
Adds an integration test (
test-aurora-failover-readonly.test.cjs) that simulates the failover using a mock server:threadId)