Skip to content

Commit d0350d1

Browse files
committed
kgo: fix sharded-request "minor" data race introduced in 1.20.3
Low impact, the sharded request "avoid broker" logic introduced in 1.20.3 did not create loop-local variables, meaning the goroutines started in each iteration of the loop all shared the same integer. Closes #1168.
1 parent 566201c commit d0350d1

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎pkg/kgo/client.go‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,9 +2482,13 @@ func (cl *Client) handleShardedReq(ctx context.Context, req kmsg.Request) ([]Res
24822482
}
24832483

24842484
for i := range issues {
2485-
myIssue := issues[i]
2486-
var isPinned bool
2487-
ctx := ctx // loop local context, in case we override by pinning
2485+
var (
2486+
myIssue = issues[i]
2487+
isPinned bool
2488+
ctx = ctx // loop local context, in case we override by pinning
2489+
avoidBroker = avoidBroker // same
2490+
tries = try.tries // same
2491+
)
24882492
if isPinned = myIssue.pin != nil; isPinned {
24892493
ctx = context.WithValue(ctx, ctxPinReq, myIssue.pin)
24902494
}
@@ -2494,7 +2498,6 @@ func (cl *Client) handleShardedReq(ctx context.Context, req kmsg.Request) ([]Res
24942498
continue
24952499
}
24962500

2497-
tries := try.tries
24982501
wg.Add(1)
24992502
go func() {
25002503
defer wg.Done()

0 commit comments

Comments
 (0)