Skip to content

Commit

Permalink
fix: closed connection error
Browse files Browse the repository at this point in the history
  • Loading branch information
ditschedev committed Apr 18, 2023
1 parent dcd8ee5 commit c97c0bb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ func (c *Conn) handle(cmd string, arg string) {
c.Close()

stack := debug.Stack()
c.server.Logger.Error(nil, fmt.Sprintf("panic serving %v: %v\n%s", c.conn.RemoteAddr(), err, stack))
if c.conn != nil {
c.server.Logger.Error(nil, fmt.Sprintf("panic serving %v: %v\n%s", c.conn.RemoteAddr(), err, stack))
} else {
c.server.Logger.Error(nil, fmt.Sprintf("panic serving closed connection: %v\n%s", err, stack))
}
}
}()

Expand Down Expand Up @@ -182,7 +186,13 @@ func (c *Conn) Close() error {
c.session = nil
}

return c.conn.Close()
if c.conn != nil {
err := c.conn.Close()
c.conn = nil
return err
}

return nil
}

// TLSConnectionState returns the connection's TLS connection state.
Expand Down

0 comments on commit c97c0bb

Please sign in to comment.