Skip to content

Commit

Permalink
Check if connection exists before trying to close it
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafa committed Oct 15, 2023
1 parent f201736 commit fa790c6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions network/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fa790c6

Please sign in to comment.