Skip to content

Commit c6f7f9a

Browse files
committed
kgo: allow empty groups when finding coordinator / fetching offsets
v1.10.0 introduced a bug when switching to batch loadCoordinators: we would strip empty coordinator keys from the request. Technically, empty coordinator keys are valid. If a request contains an empty coordinator key (empty group), we would not load it and not set a map key for it and then using a field in the map value would panic. Now, we always request all coordinator keys. This also showed a bug in sharded OffsetFetch: fetching offsets for a group with no name would be stripped (now we will just forward whatever error happens). Closes #283.
1 parent b746123 commit c6f7f9a

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

pkg/kgo/client.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -1154,9 +1154,7 @@ func (cl *Client) loadCoordinators(ctx context.Context, typ int8, keys ...string
11541154

11551155
toRequest := make(map[string]bool, len(keys)) // true == bypass the cache
11561156
for _, key := range keys {
1157-
if len(key) > 0 {
1158-
toRequest[key] = false
1159-
}
1157+
toRequest[key] = false
11601158
}
11611159

11621160
// For each of these keys, we have two cases:
@@ -2324,9 +2322,7 @@ func (cl *offsetFetchSharder) shard(ctx context.Context, kreq kmsg.Request, last
23242322
}
23252323
groups := make([]string, 0, len(req.Groups))
23262324
for i := range req.Groups {
2327-
if g := req.Groups[i].Group; len(g) > 0 {
2328-
groups = append(groups, req.Groups[i].Group)
2329-
}
2325+
groups = append(groups, req.Groups[i].Group)
23302326
}
23312327

23322328
coordinators := cl.loadCoordinators(ctx, coordinatorTypeGroup, groups...)
@@ -2487,9 +2483,7 @@ func (*findCoordinatorSharder) shard(_ context.Context, kreq kmsg.Request, lastE
24872483
}
24882484
req.CoordinatorKeys = req.CoordinatorKeys[:0]
24892485
for key := range uniq {
2490-
if len(key) > 0 {
2491-
req.CoordinatorKeys = append(req.CoordinatorKeys, key)
2492-
}
2486+
req.CoordinatorKeys = append(req.CoordinatorKeys, key)
24932487
}
24942488

24952489
splitReq := errors.Is(lastErr, errBrokerTooOld)

0 commit comments

Comments
 (0)