From f37a350adf8b7b7d535aacc918f7bded274453a6 Mon Sep 17 00:00:00 2001 From: liuzhihang1 Date: Sat, 15 Feb 2025 23:34:58 +0800 Subject: [PATCH] ws connect bug fix --- internal/app/api/ws.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/internal/app/api/ws.go b/internal/app/api/ws.go index fb4a7b5..12e5668 100644 --- a/internal/app/api/ws.go +++ b/internal/app/api/ws.go @@ -91,6 +91,7 @@ func (w *wsApi) startWsConnect(conn *websocket.Conn, proc logic.Process, write b _, b, err := conn.ReadMessage() if err != nil { log.Logger.Debugw("ws读取线程已退出", "info", err) + conn.Close() return } if write { @@ -99,4 +100,22 @@ func (w *wsApi) startWsConnect(conn *websocket.Conn, proc logic.Process, write b } } }() + // // health check + // pongChan := make(chan struct{}) + // conn.SetPongHandler(func(appData string) error { + // pongChan <- struct{}{} + // return nil + // }) + // timer := time.NewTicker(time.Second) + // go func() { + // for { + // conn.WriteMessage(websocket.PingMessage, nil) + // select { + // case <-pongChan: + // timer.Reset(time.Second) + // case <-timer.C: + // conn.Close() + // } + // } + // }() }