mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-18 07:13:50 +01:00
fix(websocket): ensure proper connection closure and stop ping check ticker in Close method
This commit is contained in:
@@ -185,18 +185,15 @@ func (cm *Manager) ReadJSON(out any, timeout time.Duration) error {
|
||||
// Close closes the connection and cancels the context
|
||||
func (cm *Manager) Close() {
|
||||
cm.cancel()
|
||||
cm.pingCheckTicker.Stop()
|
||||
cm.conn.Close()
|
||||
}
|
||||
|
||||
func (cm *Manager) GracefulClose() {
|
||||
cm.writeLock.Lock()
|
||||
defer cm.writeLock.Unlock()
|
||||
|
||||
_ = cm.conn.SetWriteDeadline(time.Now().Add(5 * time.Second))
|
||||
_ = cm.conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
|
||||
cm.conn.Close()
|
||||
|
||||
cm.Close()
|
||||
cm.pingCheckTicker.Stop()
|
||||
}
|
||||
|
||||
// Done returns a channel that is closed when the context is done or the connection is closed
|
||||
|
||||
Reference in New Issue
Block a user