Skip to content

Commit

Permalink
kadm: do not reuse ApiVersions in many concurrent requests
Browse files Browse the repository at this point in the history
The client calls SetVersion internally per request, so doing this
concurrently leads to races.
  • Loading branch information
twmb committed Oct 21, 2023
1 parent 6a961da commit 1955938
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/kadm/acls.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ func (cl *Client) DescribeACLs(ctx context.Context, b *ACLBuilder) (DescribeACLs
)
defer cancel()
for i := range descs {
req := descs[i]
req := descs[i] // each req is unique per loop, we are not reusing req, this is safe
myIdx := i
wg.Add(1)
go func() {
Expand Down
7 changes: 3 additions & 4 deletions pkg/kadm/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,6 @@ func (cl *Client) ApiVersions(ctx context.Context) (BrokersApiVersions, error) {
return nil, err
}

req := kmsg.NewPtrApiVersionsRequest()
req.ClientSoftwareName = "kadm"
req.ClientSoftwareVersion = softwareVersion()

var mu sync.Mutex
var wg sync.WaitGroup
vs := make(BrokersApiVersions, len(m.Brokers))
Expand All @@ -256,6 +252,9 @@ func (cl *Client) ApiVersions(ctx context.Context) (BrokersApiVersions, error) {
wg.Add(1)
go func() {
defer wg.Done()
req := kmsg.NewPtrApiVersionsRequest()
req.ClientSoftwareName = "kadm"
req.ClientSoftwareVersion = softwareVersion()
v := BrokerApiVersions{NodeID: n, keyVersions: make(map[int16]minmax)}
v.raw, v.Err = req.RequestWith(ctx, cl.cl.Broker(int(n)))

Expand Down

0 comments on commit 1955938

Please sign in to comment.