Fix unbounded reconnect loop when all hosts fail during connect - #1188
Open
steobrien wants to merge 1 commit into
Open
Fix unbounded reconnect loop when all hosts fail during connect#1188steobrien wants to merge 1 commit into
steobrien wants to merge 1 commit into
Conversation
steobrien
marked this pull request as ready for review
August 7, 2026 21:56
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.
Connection's localretriescounter is read in two places —error()'soptions.host[retries + 1]guard andtryNext()'soptions.host[retries]— and reset in the ready handler, but nothing ever increments it (closed()bumpsoptions.shared.retriesinstead, and for connecting sockets it returns early before reaching that line anyway).So with multiple hosts configured, a connect-phase failure always finds a "next host":
error()swallows it,closed()reconnects, forever. The pending query never settles:This change counts each failed attempt in
closed()and stops reconnecting once the host list is exhausted. A socket error on the last host already rejects the pending query inerror()with the original error (e.g.ECONNREFUSED), and a clean close with no hosts left now rejects withCONNECTION_CLOSED. The counter resets when the cycle ends, so the next query sweeps the full host list again; a successful connect resets it as before.The added test mirrors the existing single-host
ECONNREFUSEDtest — it times out on master and passes with the fix.