fix(pubsub): avoid panics on Channel conflict and Ring empty subscribe - #3968
VedantMadane wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 924803beea
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 924803b. Configure here.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0d618f37c6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
0d618f3 to
f4bdddd
Compare
|
@VedantMadane thank you for this, Ring is not officially supported or recommended anymore, but I will take a look when possible. |
e2a2d47 to
ae9a04f
Compare
ndyakov
left a comment
There was a problem hiding this comment.
Thanks for tackling this — approach looks right and matches the TODO/issue, and keeping the signatures non-breaking is the right call. A couple of things before merge, main ones being a dead stickyErr write in Close() and the Ring sticky-error path hanging silently when consumed via Channel(). Details inline.
Conflict-path logging used getContext(), which reads c.cmd while the other Channel Receive loop may write it — fails CI under -race. Closes nothing; Refs redis#3761
Match SingleConnPool.Close by setting stickyErr to ErrClosed so failed Ring PubSub Channel receivers always observe the closed exit signal. Add .gitattributes to keep Go sources on LF.
… and docs - Remove dead stickyErr write in Close() - Short-circuit Channel() and ChannelWithSubscriptions() when stickyErr is set to return an already-closed channel and log a warning - Add warning log in failedPubSub for visibility - Update doc comments for Subscribe/PSubscribe/SSubscribe and Channel methods - Remove repo-wide .gitattributes Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
7a07145 to
dc6f17e
Compare
|
Addressed in dc6f17e:
|

Summary
Fixes #3761.
PubSub.Channel/ChannelWithSubscriptionsmutual-exclusion misuse no longer panics; returns a closed channel and logs a warning.Ring.Subscribe/PSubscribe/SSubscribeno longer panic on empty channels or shard lookup failure; return a PubSub with a sticky error (as the existing TODO suggested).Test plan
TestRingSubscribeEmptyChannelsNoPanicTestPubSubChannelMutualExclusionNoPanicNote
Medium Risk
Changes PubSub failure semantics from panic to errors/closed channels; callers that relied on panics or expected blocking on misuse may see different behavior, though it is generally safer for production.
Overview
Fixes #3761 by replacing several PubSub panics with recoverable behavior.
Ring
Subscribe/PSubscribe/SSubscribeno longer panic when channels are missing or shard lookup fails (e.g. empty ring). They return aPubSubbuilt viafailedPubSubthat carries astickyErr, whichconn()andReceive*surface as errors instead of crashing at construction.PubSub.ChannelandChannelWithSubscriptionsnow handle two failure modes without panicking: sticky construction errors, and calling the “wrong” channel API after the other was already used. Both paths log a warning and return an already-closed Go channel (logging usescontext.Background()to avoid a race onc.cmd).Tests cover Ring empty subscribe, channel API conflicts, and Ginkgo cases for sticky-error channels.
Reviewed by Cursor Bugbot for commit dc6f17e. Bugbot is set up for automated code reviews on this repo. Configure here.