From f878f81548dfa5c4e83c4bd937caf5f8fbc120ab Mon Sep 17 00:00:00 2001 From: Joshua Powers Date: Mon, 7 Mar 2022 13:54:06 -0700 Subject: [PATCH] fix: check connection before closing A user of Telegraf reported a panic when the client was trying to close the connection, but it was already closed. See influxdata/telegraf#10595 for more details. --- client.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 1ab9e14d..3d3ef2ed 100644 --- a/client.go +++ b/client.go @@ -585,7 +585,9 @@ func (c *Client) CloseWithContext(ctx context.Context) error { // close the connection but ignore the error since there isn't // anything we can do about it anyway - c.conn.Close() + if c.conn != nil { + c.conn.Close() + } return nil }