From fa790c6fda76cfdc4b40e4712a947cd6da6ac1d2 Mon Sep 17 00:00:00 2001 From: Mostafa Moradian Date: Sun, 15 Oct 2023 16:16:30 +0200 Subject: [PATCH] Check if connection exists before trying to close it --- network/client.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/network/client.go b/network/client.go index 27c119a4..05408ff4 100644 --- a/network/client.go +++ b/network/client.go @@ -273,9 +273,11 @@ func (c *Client) Close() { // Set the deadline to now so that the connection is closed immediately. // This will stop all the Conn.Read() and Conn.Write() calls. // Ref: https://groups.google.com/g/golang-nuts/c/VPVWFrpIEyo - if err := c.conn.SetDeadline(time.Now()); err != nil { - c.logger.Error().Err(err).Msg("Failed to set deadline") - span.RecordError(err) + if c.conn != nil { + if err := c.conn.SetDeadline(time.Now()); err != nil { + c.logger.Error().Err(err).Msg("Failed to set deadline") + span.RecordError(err) + } } c.connected.Store(false)