Repository navigation
fix(consumer): stop roundrobin balancer looping on an unsubscribed topic - #3740
Merged
Merged
Conversation
roundRobinBalancer.Plan searched members[i%n] forever when the topics map held a topic no member subscribes to. Bound the search to one pass over the members and leave such a topic unassigned, as the range and sticky strategies do. When a subscriber exists the same member is chosen and the cursor advances by the same amount, so existing plans do not change. Signed-off-by: Jeff Lenamon <jlenamon@gmail.com>
lenamonj
force-pushed
the
roundrobin-unsubscribed-topic
branch
from
September 13, 2026 18:06
e02d71f to
0520471
Compare
puellanivis
reviewed
Sep 15, 2026
Comment on lines
453
to
459
| probe := 0 | ||
| for probe < n && !members[(i+probe)%n].hasTopic(tp.topic) { | ||
| probe++ | ||
| } | ||
| if probe == n { | ||
| continue // no member subscribes to this topic | ||
| } |
Collaborator
There was a problem hiding this comment.
🤔 We could probably do this by reworking the existing control flow instead:
m := member[i%n]
for range len(members) {
if m.hasTopic(tp.topic) {
break
}
i++
m = member[i%n]
}
if !m.hasTopic(tp.topic) {
continue // no member subscribes to this topic
}… cursor Rework the subscriber search as the reviewer suggested: advance the existing member cursor inside a loop bounded by the member count and skip the topic when the cursor comes back without a subscriber. Signed-off-by: Jeff Lenamon <jlenamon@gmail.com>
Contributor
Author
|
Reworked to your form in the second commit; the same member is chosen and the cursor advances by the same amount, so the added test row and the existing rows still pass. |
dnwe
approved these changes
Sep 20, 2026
dnwe
left a comment
Collaborator
There was a problem hiding this comment.
Thanks! Great contribution – lgtm
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.
roundRobinBalancer.Plannever returns when the topics map holds a topic no member subscribes to: the subscriber search walksmembers[i%n]forever. The range and sticky strategies leave such a topic unassigned.The search is now bounded to one pass over the members and a topic with no subscriber is skipped. Whenever a subscriber exists the same member is chosen and the cursor advances by the same amount, so existing plans are unchanged.
Sarama's own consumer group builds the topics map from the members' subscriptions, so this reaches direct callers of
Plan.A row added to
TestBalanceStrategyRoundRobincovers it; on main that row hangs until the test timeout.