Repository navigation
fix(cluster): split a cross-slot SUNSUBSCRIBE per slot - #132
Merged
Merged
Conversation
A single SSUBSCRIBE must name one slot, but a PubSubStream may add shard channels of other slots afterwards through `PubSubStream::ssubscribe`. `close` and `Drop` then released them all in one SUNSUBSCRIBE, which the cluster connection routed as a single-slot command and refused at feed time with `MismatchedKeySlots`. `close` returned the error, `Drop` swallowed it, every subscription stayed on its master, and the next command on the same client could stall. A SUNSUBSCRIBE naming several slots is now routed through the multi-shard policy, one slice per slot. The acknowledgements are matched per channel by the router, so the caller is answered once every master has confirmed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Jo8jBqM8KTsnpJz9oRkK5G
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.
Problem
A single
SSUBSCRIBEmust name one slot, but aPubSubStreammay add shard channels of other slots afterwards throughPubSubStream::ssubscribe.closeandDropthen released them all in oneSUNSUBSCRIBE, which the cluster connection routed as a single-slot command and refused at feed time withMismatchedKeySlots:closereturned the error;Dropswallowed it (fire-and-forget);ssubscribeon the sameClientstalled (observed: the new test hangs onmain).Note: the reported reproduction (
client.ssubscribe(["doc:{a}", "doc:{b}"])) actually fails earlier, at the subscription itself, withMismatchedKeySlots. The leak happens when a stream accumulates slots onessubscribeat a time.Fix
A
SUNSUBSCRIBEnaming several slots is routed through the multi-shard policy, one slice per slot (not per node: Redis refuses a cross-slotSUNSUBSCRIBEeven when both slots live on the same node). The router matches acknowledgements per channel, so the caller is answered once every master has confirmed. A single-slotSUNSUBSCRIBEkeeps the cheaper single-shard path.Tests
dropping_a_shard_stream_spanning_slots_releases_every_slot_in_cluster: drop, re-subscribe, and check messages arrive from both masters. Hangs onmain, passes here.closing_a_shard_stream_spanning_slots_succeeds_in_cluster:closeand an explicit cross-slotsunsubscribe. Fails onmain, passes here../run_tests.sh --hermeticand clippy clean. Pub/sub and cluster suites run against a local 3-master cluster: no new failure (the remaining ones need replicas / spare nodes / Redis 8 and fail identically onmain).Generated by Claude Code