mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 00:38:33 +02: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
|
// Close closes the connection and cancels the context
|
||||||
func (cm *Manager) Close() {
|
func (cm *Manager) Close() {
|
||||||
cm.cancel()
|
cm.cancel()
|
||||||
cm.pingCheckTicker.Stop()
|
|
||||||
cm.conn.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (cm *Manager) GracefulClose() {
|
|
||||||
cm.writeLock.Lock()
|
cm.writeLock.Lock()
|
||||||
defer cm.writeLock.Unlock()
|
defer cm.writeLock.Unlock()
|
||||||
|
|
||||||
_ = cm.conn.SetWriteDeadline(time.Now().Add(5 * time.Second))
|
_ = cm.conn.SetWriteDeadline(time.Now().Add(5 * time.Second))
|
||||||
_ = cm.conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
|
_ = 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
|
// Done returns a channel that is closed when the context is done or the connection is closed
|
||||||
|
|||||||
Reference in New Issue
Block a user