Skip to content

Commit

Permalink
fix: check connection before closing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
powersj authored Mar 7, 2022
1 parent 486ed60 commit f878f81
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit f878f81

Please sign in to comment.