Skip to content

Commit

Permalink
Fix data race on Broker.done channel (#2698)
Browse files Browse the repository at this point in the history
The underlying case was not waiting for the goroutine running the
`responseReceiver()` method to fully complete if SASL authentication
failed. This created a window where a further call to `Broker.Open()`
could overwrite the `Broker.done` channel value while the goroutine
still running `responseReceiver()` was trying to close the same channel.

Fixes: #2382

Signed-off-by: Adrian Preston <[email protected]>
  • Loading branch information
prestona authored Nov 1, 2023
1 parent 82f0e48 commit a15034a
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func (b *Broker) Open(conf *Config) error {
b.connErr = b.authenticateViaSASLv1()
if b.connErr != nil {
close(b.responses)
<-b.done
err = b.conn.Close()
if err == nil {
DebugLogger.Printf("Closed connection to broker %s\n", b.addr)
Expand Down

0 comments on commit a15034a

Please sign in to comment.