Send close message when explicitly closing client.

This commit is contained in:
Joachim Bauch 2021-06-07 17:14:23 +02:00
parent 9a473b9bf1
commit 2628735431
No known key found for this signature in database
GPG Key ID: 77C1D22D53E15F02
1 changed files with 6 additions and 0 deletions

View File

@ -184,6 +184,12 @@ func (c *Client) Close() {
return
}
c.mu.Lock()
if c.conn != nil {
c.conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")) // nolint
}
c.mu.Unlock()
if atomic.LoadUint32(&c.messageProcessing) == 1 {
// Defer closing
atomic.StoreUint32(&c.closed, 2)