Repository navigation
fix(client): settle the close() drain when the last connect fails - #3400
Merged
nkaradzhov merged 1 commit intoAug 14, 2026
Merged
Conversation
nkaradzhov
approved these changes
Aug 14, 2026
nkaradzhov
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @kyungseopk1m, this looks good to go
2 of 3 tasks
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.
Description
Fixes #3398.
#create()pushes the client onto#clientsInUsebefore it awaitsclient.connect(), so a connecting client counts toward capacity. On a connect failure it removes the node directly instead of going through#returnClient(), which is the only place that resolves#drainResolve. Ifclose()was already waiting for the pool to drain,#clientsInUsereached 0 without waking it andclose()never settled.Signalling the drain from that path is not enough on its own. A task queued behind the pending connect is exactly what
close()is still waiting for, and once the connect fails there is no client left to run it on:execute()rejects new work while closing, and nothing will call#returnClient()again. So the failure path now settles those tasks with the connection error before it resolves the drain. The caller gets the real reason instead of a laterTimeoutError, or nothing at all whenacquireTimeoutis 0.This is scoped to a closing pool. While the pool is open a failed scale-up leaves the queued task on its existing
acquireTimeoutpath, which is #3397 and a separate discussion. Draining the queue here only usesshift(), so it does not touchSinglyLinkedList.remove().Two tests cover it, neither needs a server:
close()settles when the only pending connect failsclose()settles, and the task's acquire timer is cleared with it (otherwise it later fires on a node that is already out of the queue andremove()throws)Checklist
npm testpass with this change (including linting)?Note
Medium Risk
Touches pool shutdown and task-queue settlement on connect failure; behavior is scoped to closing pools but affects promise lifecycle and timers.
Overview
Fixes a hang in
RedisClientPool.close()when shutdown overlaps a failingconnect():#create()removed the in-flight client from#clientsInUseon error without invoking#returnClient(), so#drainResolvenever ran even though the pool was empty.On that path, when the pool is closing and no clients remain in use, the failure handler now drains
#tasksQueue—clearTimeouton each waiter, reject with the connect error, then call#drainResolve—so queuedexecute()work fails with the real connection error instead of waiting onacquireTimeout, andclose()can finish.Adds two no-server regression tests:
close()resolves after the only pending connect fails, and a task queued behind that connect is rejected, timers are cleared, andclose()still completes.Reviewed by Cursor Bugbot for commit 274ffd3. Bugbot is set up for automated code reviews on this repo. Configure here.