Skip to content

fix(pool): discard connection on error 1290 (Aurora read-only failure)#4075

Open
natetarrh wants to merge 3 commits intosidorares:masterfrom
natetarrh:natetarrh/fix-pool-discard-readonly-on-aurora-failover
Open

fix(pool): discard connection on error 1290 (Aurora read-only failure)#4075
natetarrh wants to merge 3 commits intosidorares:masterfrom
natetarrh:natetarrh/fix-pool-discard-readonly-on-aurora-failover

Conversation

@natetarrh
Copy link

@natetarrh natetarrh commented Feb 12, 2026

Problem

During an Aurora MySQL failover, an existing writable connection becomes read-only. Subsequent writes return error 1290 (ER_OPTION_PREVENTS_STATEMENT):

The MySQL server is running with the --read-only option so it cannot execute this 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 ErrBadConn when it encounters errors 1290, 1792, or 1836 during failover. This causes Go's database/sql pool 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() and pool.execute() now detect error 1290 and call conn.destroy() instead of conn.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:

  1. Pool gets a connection, first query succeeds
  2. Mock server starts returning error 1290 (simulating failover)
  3. Asserts the pool discards the bad connection and provides a new one (different threadId)

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>
@natetarrh natetarrh marked this pull request as ready for review February 12, 2026 23:32
@natetarrh natetarrh changed the title fix(pool): discard connection on error 1290 (Aurora failover read-only) fix(pool): discard connection on error 1290 (Aurora read-only failure) Feb 12, 2026
@codecov
Copy link

codecov bot commented Feb 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.94%. Comparing base (b0f8a77) to head (379139b).
⚠️ Report is 2 commits behind head on master.

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     
Flag Coverage Δ
compression-0 89.06% <100.00%> (+0.08%) ⬆️
compression-1 89.92% <100.00%> (+0.07%) ⬆️
static-parser-0 87.53% <100.00%> (+0.08%) ⬆️
static-parser-1 88.29% <100.00%> (+0.08%) ⬆️
tls-0 89.35% <100.00%> (+0.07%) ⬆️
tls-1 89.72% <100.00%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

read-only error on aws aurora mysql failover action

1 participant