From a721a20b35c78d6e4ca9490942dd1b5ad0cb3d83 Mon Sep 17 00:00:00 2001 From: Pierangelo Di Pilato Date: Tue, 1 Oct 2024 14:51:29 +0200 Subject: [PATCH 1/2] Log SASL connection and handshake errors I'm trying to debug an issue and the logger is only logging: `Error while performing SASL handshake kafka-1:9093` since the actual error is not logged, it's not clear what went wrong. Signed-off-by: Pierangelo Di Pilato --- broker.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/broker.go b/broker.go index d38fc9662..92fcd86f0 100644 --- a/broker.go +++ b/broker.go @@ -243,9 +243,9 @@ func (b *Broker) Open(conf *Config) error { if b.connErr != nil { err = b.conn.Close() if err == nil { - DebugLogger.Printf("Closed connection to broker %s\n", b.addr) + DebugLogger.Printf("Closed connection to broker %s due to SASL v0 auth error: %s\n", b.addr, b.connErr.Error()) } else { - Logger.Printf("Error while closing connection to broker %s: %s\n", b.addr, err) + Logger.Printf("Error while closing connection to broker %s (due to SASL v0 auth error: %s): %s\n", b.addr, b.connErr.Error(), err) } b.conn = nil atomic.StoreInt32(&b.opened, 0) @@ -264,9 +264,9 @@ func (b *Broker) Open(conf *Config) error { <-b.done err = b.conn.Close() if err == nil { - DebugLogger.Printf("Closed connection to broker %s\n", b.addr) + DebugLogger.Printf("Closed connection to broker %s due to SASL v1 auth error: %s\n", b.addr, b.connErr.Error()) } else { - Logger.Printf("Error while closing connection to broker %s: %s\n", b.addr, err) + Logger.Printf("Error while closing connection to broker %s (due to SASL v1 auth error: %s): %s\n", b.addr, b.connErr.Error(), err) } b.conn = nil atomic.StoreInt32(&b.opened, 0) @@ -1242,12 +1242,12 @@ func (b *Broker) authenticateViaSASLv1() error { handshakeErr := b.sendInternal(handshakeRequest, prom) if handshakeErr != nil { - Logger.Printf("Error while performing SASL handshake %s\n", b.addr) + Logger.Printf("Error while performing SASL handshake %s: %s\n", b.addr, handshakeErr.Error()) return handshakeErr } handshakeErr = handleResponsePromise(handshakeRequest, handshakeResponse, prom, metricRegistry) if handshakeErr != nil { - Logger.Printf("Error while performing SASL handshake %s\n", b.addr) + Logger.Printf("Error while handling SASL handshake response %s: %s\n", b.addr, handshakeErr.Error()) return handshakeErr } @@ -1267,7 +1267,7 @@ func (b *Broker) authenticateViaSASLv1() error { } authErr = handleResponsePromise(authenticateRequest, authenticateResponse, prom, metricRegistry) if authErr != nil { - Logger.Printf("Error while performing SASL Auth %s\n", b.addr) + Logger.Printf("Error while performing SASL Auth %s: %s\n", b.addr, authErr.Error()) return nil, authErr } @@ -1385,7 +1385,7 @@ func (b *Broker) sendAndReceiveSASLPlainAuthV0() error { if b.conf.Net.SASL.Handshake { handshakeErr := b.sendAndReceiveSASLHandshake(SASLTypePlaintext, b.conf.Net.SASL.Version) if handshakeErr != nil { - Logger.Printf("Error while performing SASL handshake %s\n", b.addr) + Logger.Printf("Error while performing SASL handshake %s: %s\n", b.addr, handshakeErr.Error()) return handshakeErr } } From 57b7bb87dbc4cd6eb480cd602579a1d817db20bd Mon Sep 17 00:00:00 2001 From: Pierangelo Di Pilato Date: Tue, 1 Oct 2024 16:15:32 +0200 Subject: [PATCH 2/2] Remove unnecessary .Error() Signed-off-by: Pierangelo Di Pilato --- broker.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/broker.go b/broker.go index 92fcd86f0..d5f7c4ab9 100644 --- a/broker.go +++ b/broker.go @@ -243,9 +243,9 @@ func (b *Broker) Open(conf *Config) error { if b.connErr != nil { err = b.conn.Close() if err == nil { - DebugLogger.Printf("Closed connection to broker %s due to SASL v0 auth error: %s\n", b.addr, b.connErr.Error()) + DebugLogger.Printf("Closed connection to broker %s due to SASL v0 auth error: %s\n", b.addr, b.connErr) } else { - Logger.Printf("Error while closing connection to broker %s (due to SASL v0 auth error: %s): %s\n", b.addr, b.connErr.Error(), err) + Logger.Printf("Error while closing connection to broker %s (due to SASL v0 auth error: %s): %s\n", b.addr, b.connErr, err) } b.conn = nil atomic.StoreInt32(&b.opened, 0) @@ -264,9 +264,9 @@ func (b *Broker) Open(conf *Config) error { <-b.done err = b.conn.Close() if err == nil { - DebugLogger.Printf("Closed connection to broker %s due to SASL v1 auth error: %s\n", b.addr, b.connErr.Error()) + DebugLogger.Printf("Closed connection to broker %s due to SASL v1 auth error: %s\n", b.addr, b.connErr) } else { - Logger.Printf("Error while closing connection to broker %s (due to SASL v1 auth error: %s): %s\n", b.addr, b.connErr.Error(), err) + Logger.Printf("Error while closing connection to broker %s (due to SASL v1 auth error: %s): %s\n", b.addr, b.connErr, err) } b.conn = nil atomic.StoreInt32(&b.opened, 0) @@ -1242,12 +1242,12 @@ func (b *Broker) authenticateViaSASLv1() error { handshakeErr := b.sendInternal(handshakeRequest, prom) if handshakeErr != nil { - Logger.Printf("Error while performing SASL handshake %s: %s\n", b.addr, handshakeErr.Error()) + Logger.Printf("Error while performing SASL handshake %s: %s\n", b.addr, handshakeErr) return handshakeErr } handshakeErr = handleResponsePromise(handshakeRequest, handshakeResponse, prom, metricRegistry) if handshakeErr != nil { - Logger.Printf("Error while handling SASL handshake response %s: %s\n", b.addr, handshakeErr.Error()) + Logger.Printf("Error while handling SASL handshake response %s: %s\n", b.addr, handshakeErr) return handshakeErr } @@ -1267,7 +1267,7 @@ func (b *Broker) authenticateViaSASLv1() error { } authErr = handleResponsePromise(authenticateRequest, authenticateResponse, prom, metricRegistry) if authErr != nil { - Logger.Printf("Error while performing SASL Auth %s: %s\n", b.addr, authErr.Error()) + Logger.Printf("Error while performing SASL Auth %s: %s\n", b.addr, authErr) return nil, authErr } @@ -1385,7 +1385,7 @@ func (b *Broker) sendAndReceiveSASLPlainAuthV0() error { if b.conf.Net.SASL.Handshake { handshakeErr := b.sendAndReceiveSASLHandshake(SASLTypePlaintext, b.conf.Net.SASL.Version) if handshakeErr != nil { - Logger.Printf("Error while performing SASL handshake %s: %s\n", b.addr, handshakeErr.Error()) + Logger.Printf("Error while performing SASL handshake %s: %s\n", b.addr, handshakeErr) return handshakeErr } }