mirror of
https://github.com/lzh-1625/go_process_manager.git
synced 2025-10-05 16:06:51 +08:00
optimal ws health check
This commit is contained in:
@@ -113,7 +113,7 @@ func (w *wsApi) startWsConnect(wci *WsConnetInstance, cancel context.CancelFunc,
|
||||
pongChan <- struct{}{}
|
||||
return nil
|
||||
})
|
||||
timer := time.NewTicker(time.Second * time.Duration(config.CF.WsHealthCheckInterval))
|
||||
timer := time.NewTicker(time.Second)
|
||||
go func() {
|
||||
defer timer.Stop()
|
||||
for {
|
||||
@@ -121,13 +121,13 @@ func (w *wsApi) startWsConnect(wci *WsConnetInstance, cancel context.CancelFunc,
|
||||
wci.WsConnect.WriteMessage(websocket.PingMessage, nil)
|
||||
wci.wsLock.Unlock()
|
||||
select {
|
||||
case <-pongChan:
|
||||
timer.Reset(time.Second * time.Duration(config.CF.WsHealthCheckInterval))
|
||||
case <-timer.C:
|
||||
log.Logger.Debugw("pong报文超时,结束ws连接")
|
||||
cancel()
|
||||
return
|
||||
case <-pongChan:
|
||||
}
|
||||
time.Sleep(time.Second * time.Duration(config.CF.WsHealthCheckInterval))
|
||||
timer.Reset(time.Second)
|
||||
}
|
||||
}()
|
||||
|
||||
|
Reference in New Issue
Block a user