Skip to content

fix(pubsub): avoid panics on Channel conflict and Ring empty subscribe - #3968

Open
VedantMadane wants to merge 4 commits into
redis:masterfrom
VedantMadane:fix-issue-3761
Open

fix(pubsub): avoid panics on Channel conflict and Ring empty subscribe#3968
VedantMadane wants to merge 4 commits into
redis:masterfrom
VedantMadane:fix-issue-3761

Conversation

@VedantMadane

@VedantMadane VedantMadane commented Aug 17, 2026

Copy link
Copy Markdown

Summary

Fixes #3761.

  • PubSub.Channel / ChannelWithSubscriptions mutual-exclusion misuse no longer panics; returns a closed channel and logs a warning.
  • Ring.Subscribe / PSubscribe / SSubscribe no longer panic on empty channels or shard lookup failure; return a PubSub with a sticky error (as the existing TODO suggested).

Test plan

  • TestRingSubscribeEmptyChannelsNoPanic
  • TestPubSubChannelMutualExclusionNoPanic

Note

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 / SSubscribe no longer panic on empty channel lists or shard lookup failure. They return a failedPubSub handle that carries a stickyErr; Receive and connection setup surface that error instead of crashing at construction.

PubSub gains stickyErr handling in conn (fail fast before dialing) and Close now overwrites a construction-time sticky error with pool.ErrClosed so Channel() pump goroutines can exit cleanly—aligned with SingleConnPool.Close.

Calling Channel after ChannelWithSubscriptions (or the reverse) no longer panics: the conflicting call logs a warning and returns an already-closed Go channel (logging uses context.Background to avoid racing on c.cmd).

Also adds .gitattributes for 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread pubsub.go Outdated
Comment thread pubsub.go Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 924803b. Configure here.

Comment thread pubsub.go Outdated
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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread pubsub.go Outdated
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.
@ndyakov

ndyakov commented Aug 18, 2026

Copy link
Copy Markdown
Member

@VedantMadane thank you for this, Ring is not officially supported or recommended anymore, but I will take a look when possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PubSub.Channel and Ring.Subscribe/PSubscribe/SSubscribe panic instead of returning error

2 participants