Repository navigation
fix(cluster): drop the source connection when the in-flight flush runs during slot migration - #3642
Merged
nkaradzhov merged 1 commit intoNov 19, 2026
Conversation
Codex Review Summary: ✅ CompletedThis 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. |
Collaborator
|
Thanks. #3641 is merged, so this PR now conflicts with master. Please rebase on master and drop the first commit ( |
…s during slot migration When the 5s in-flight wait times out during SMIGRATED handling, the pending commands are rejected and the reply queue is emptied, but the socket stays open. The server may still send the replies for the flushed commands, and since RESP pairing is positional the queue hands them to whatever was sent after the flush - late replies resolve the wrong commands, or crash the decoder on shift() when nothing was sent. waitForInflightCommandsToComplete now reports whether it flushed, and the SMIGRATED path drops the connection of every client whose flush ran before unpausing it, through the same error-and-reconnect handling a decoder error uses. A fresh connection gets no late replies. A source that lost all its slots is unaffected - its clients are destroyed anyway. Fixes redis#3635
Cdineshreddy12
force-pushed
the
fix/smigrated-desynced-socket
branch
from
November 19, 2026 11:51
8d0cef2 to
6245561
Compare
Contributor
Author
This was referenced Nov 19, 2026
Closed
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.
Fixes #3635
Implements the close-and-reconnect direction from my comment on the issue — if maintainers prefer a different approach happy to rework.
Two pieces:
waitForInflightCommandsToCompletenow resolves a boolean:trueonly when the timeout fired and pending commands were actually flushed. The one other caller (enterprise-maintenance-manager) ignores the return value, so nothing else changes.SMIGRATEDpath, every client whose flush ran gets its connection dropped before the unpause, via a new internal_resetDesyncedConnectionthat resets the decoder and callssocket.failConnection()— the same error-and-reconnect treatment a decoder error already gets in#attachListeners, since it's the same situation: replies on the wire that can no longer be matched to commands. The regular reconnect machinery brings up a clean connection and handles the pub/sub clients' resubscribes.A source that lost all its slots is untouched by this — its clients get
destroy()ed in step 7 anyway, so late replies die with them. Same for theshift()on an empty queue turning into a decoder TypeError: nothing old can arrive on the new socket.Tests: four unit tests in
commands-queue.spec.tscovering the new return value (nothing in flight, completed within timeout, flushed on timeout, timeout without flushOnTimeout). The cluster-side behavior needs a migrating cluster to exercise end-to-end, which the docker harness can't do on my machine (--network hoston Docker for Mac, same limitation I hit on #3641) — the full queue spec (74 tests) and the build pass locally, and I verified the flush path rejects withTimeoutErroras before.Note
Medium Risk
Changes cluster slot-migration connection teardown when in-flight commands are flushed; incorrect handling could mis-pair RESP replies or leave a bad connection alive, but scope is limited to the SMIGRATED timeout path and sources that still retain slots.
Overview
Fixes #3635 by treating a timeout-driven in-flight command flush during cluster slot migration as a desynced socket that must not be reused.
waitForInflightCommandsToCompletenow returns a boolean (trueonly when the wait timed out andflushOnTimeoutactually flushed pending replies). ClusterSMIGRATEDhandling uses that signal: any source/pub-sub client that was flushed gets_resetDesyncedConnection(decoder reset +failConnection, same path as a decoder error) before the source is unpaused, so late server replies cannot pair with the wrong commands on positional RESP.Adds four queue unit tests for the new return semantics.
Reviewed by Cursor Bugbot for commit 6245561. Bugbot is set up for automated code reviews on this repo. Configure here.