From ed4d89cfe7e8fd2613576620673705bdabca0024 Mon Sep 17 00:00:00 2001 From: Adrian Preston Date: Tue, 31 Oct 2023 21:56:18 +0000 Subject: [PATCH] Fix data race on Broker.done channel 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 --- broker.go | 1 + 1 file changed, 1 insertion(+) diff --git a/broker.go b/broker.go index 7ec3022b3f..71866ed669 100644 --- a/broker.go +++ b/broker.go @@ -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)