fix(pubsub): avoid panics on Channel conflict and Ring empty subscribe - #3968
fix(pubsub): avoid panics on Channel conflict and Ring empty subscribe#3968VedantMadane wants to merge 4 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.
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
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
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.
|
@VedantMadane thank you for this, Ring is not officially supported or recommended anymore, but I will take a look when possible. |

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
Behavior change from panic to errors/closed channels affects misuse and Ring subscribe edge cases; happy-path PubSub is unchanged but shutdown and error surfacing semantics are new contract for callers.
Overview
Fixes #3761 by replacing several PubSub and Ring panics with recoverable behavior.
Ring
Subscribe/PSubscribe/SSubscribeno longer panic on empty channel lists or shard lookup failure. They return afailedPubSubhandle that carries astickyErr;Receiveand connection setup surface that error instead of crashing at construction.PubSub gains
stickyErrhandling inconn(fail fast before dialing) andClosenow overwrites a construction-time sticky error withpool.ErrClosedsoChannel()pump goroutines can exit cleanly—aligned withSingleConnPool.Close.Calling
ChannelafterChannelWithSubscriptions(or the reverse) no longer panics: the conflicting call logs a warning and returns an already-closed Go channel (logging usescontext.Backgroundto avoid racing onc.cmd).Also adds
.gitattributesfor LF line endings on common text types and unit/Ginkgo tests for the new paths.Reviewed by Cursor Bugbot for commit e2a2d47. Bugbot is set up for automated code reviews on this repo. Configure here.