From a15034a18d63feb8cf28529627834471b7b32889 Mon Sep 17 00:00:00 2001 From: Adrian Preston Date: Wed, 1 Nov 2023 10:45:36 +0000 Subject: [PATCH] Fix data race on Broker.done channel (#2698) 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 7ec3022b3..71866ed66 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)