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