Open
Conversation
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.
What changed?
DatabaseHandle.reconnect()indb_handle.gohad two closely related bugs that caused an unbounded accumulation of*sql.DBpools during sustained DB unavailability:Pool destroyed before throttle check. The old pool was nil'd out (
h.db.Store(nil)) before the throttle check. When throttled, no new pool was created, soh.dbstayed nil for the entire 1-second window. Every caller in that window gotDatabaseUnavailableError, triggering anotherConvertError→reconnect(true)→ destroy pool → throttled → nil again — a loop that lasted the entire outage.New pool created before old one closed. On each un-throttled reconnect, a fresh
*sql.DBwas opened while the previous one was closed asynchronously. During a 2-3 minute outage (~150 throttle windows), ~150 generations of pools accumulated. On recovery, all of them raced to open connections simultaneously, blowing throughmaxConnsby a factor of ~150.The fix: move the
nil+go prevConn.Close()to after a successful new connection is established, and return the existing pool when throttled rather than returningnil.Why?
Fixes #9747
How did you test it?
TestReconnectPoolAccumulationDuringOutageandTestReconnectNilPoolOnThrottleindb_handle_test.godirectly reproduce both failure modesPotential risks
DatabaseUnavailableErrorimmediately. This is intentional —ConvertErrorstill detects individual connection errors, retriggersreconnect(true), and the throttle ensures we attempt at most one reconnect per second. The overall behaviour is strictly better under sustained outages.