Repository navigation
fix: end when quit() or disconnect() is called while reconnecting - #2245
Merged
PavelPashov merged 1 commit intoOct 23, 2026
Merged
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
snapotter-hq
added a commit
to snapotter-hq/SnapOtter
that referenced
this pull request
Oct 23, 2026
… grids via Sharp (#3604) Calling disconnect(false) on an ioredis client in the "reconnecting" state cancels reconnectTimeout and invokes connector.disconnect() on the already closed socket from the prior connection, so "end" never fires and BullMQ's Worker.close() hangs in afterAll after a >6s event-loop stall trips the waitForJob watchdog. Patch Redis.prototype.disconnect in connection.ts (matching upstream redis/ioredis#2245) to transition reconnecting clients to "end" and flush both active and saved command queues when reconnect is false. In qr-generate.ts, rasterize the QR module matrix at 1 pixel per module and upscale with Sharp nearest-neighbor interpolation instead of allocating a 400 MB RGBA buffer in pngjs at size 10000. Closes #3604
snapotter-hq
added a commit
to snapotter-hq/SnapOtter
that referenced
this pull request
Oct 23, 2026
… grids via Sharp (#3604) (#3730) Calling disconnect(false) on an ioredis client in the "reconnecting" state cancels reconnectTimeout and invokes connector.disconnect() on the already-closed socket from the prior connection, so "end" never fires and BullMQ's Worker.close() hangs in afterAll after a >6s event-loop stall trips the waitForJob watchdog. Patch Redis.prototype.disconnect in connection.ts (matching upstream redis/ioredis#2245) to transition reconnecting clients to "end" and flush offlineQueue, commandQueue, and prevCommandQueue when reconnect is false. In qr-generate.ts, rasterize the QR module matrix at 1 pixel per module and upscale with Sharp nearest-neighbor interpolation instead of allocating a 400 MB RGBA buffer in pngjs at size 10000. Closes #3604
PavelPashov
approved these changes
Oct 23, 2026
PavelPashov
left a comment
Contributor
There was a problem hiding this comment.
@bercedev LGTM, thank you for the contribution
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.
the standalone
Redisside of #2240.after a dropped connection the client is
reconnectingwith the retry timer armed.disconnect()clears the timer, but since the status isn'twaitit callsconnector.disconnect()on a socket that already closed, soclosenever comes again,closeHandlernever runs andendis never emitted. the client staysreconnectingfor good.quit()takes the same path (it callsdisconnect()when the stream isn't writable).this hangs BullMQ's
Worker.close(), which awaitsendon its blocking connection: snapotter-hq/SnapOtter#3604 has the full trace, from an event loop stall that trips BullMQ's watchdog intodisconnect(true)toclose()hanging inafterAll.in
reconnectingwithreconnect === false,disconnect()now ends the client the waycloseHandlerwould for a manual close (statusend, queues flushed) instead of waiting for aclosethat won't come. it doesn't runcloseHandleragain, because that would emit a secondclosefor the same socket.disconnect(true)while reconnecting is unchanged.tests in
test/functional/disconnection.ts, like the cluster ones:disconnect()andquit()on thereconnectingevent end the client and later commands reject withConnection is closed.. both fail on main (expected 'reconnecting' to equal 'end'). ran unit + functional against redis 7.0.15: 2333 passing, the 7 failures (zrank/zrevrank WITHSCORE, scanStream) fail the same on main with that redis version. tsc and prettier are clean.Note
Medium Risk
Touches core connection teardown in
disconnect(); behavior change is narrow (manual close during reconnect) but shutdown paths are easy to get wrong.Overview
Fixes a hang where
disconnect()orquit()duringreconnectingleft the client stuck in that state and never emittedend.After a drop, the socket is already closed and
closehas run, but a retry timer is still armed. A manualdisconnect(false)cleared the timer and calledconnector.disconnect()on a dead socket, socloseHandlernever ran again. The change adds areconnecting && !reconnectpath that finishes the shutdown inline: statusend, command queues flushed withConnection is closed., without re-invokingcloseHandler(avoids a duplicateclose).disconnect(true)while reconnecting is unchanged.Functional tests cover
disconnect()andquit()in that window and assert later commands reject.Reviewed by Cursor Bugbot for commit 1cd3eb9. Bugbot is set up for automated code reviews on this repo. Configure here.