Skip to content

Commit

Permalink
fix: data race in Broker.AsyncProduce
Browse files Browse the repository at this point in the history
Signed-off-by: Lev Zakharov <[email protected]>
  • Loading branch information
lzakharov committed Oct 26, 2023
1 parent 3ca69a8 commit c25dc27
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,11 @@ type ProduceCallback func(*ProduceResponse, error)
//
// Make sure not to Close the broker in the callback as it will lead to a deadlock.
func (b *Broker) AsyncProduce(request *ProduceRequest, cb ProduceCallback) error {
b.lock.Lock()
defer b.lock.Unlock()

metricRegistry := b.metricRegistry

needAcks := request.RequiredAcks != NoResponse
// Use a nil promise when no acks is required
var promise *responsePromise
Expand Down Expand Up @@ -465,8 +469,6 @@ func (b *Broker) AsyncProduce(request *ProduceRequest, cb ProduceCallback) error
}
}

b.lock.Lock()
defer b.lock.Unlock()
return b.sendWithPromise(request, promise)
}

Expand Down

0 comments on commit c25dc27

Please sign in to comment.