From 903cdeaa7f4ed8bbf217c3203f7dfe964c1b2559 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 17 Oct 2020 16:44:53 +0200 Subject: [PATCH] proxy: fix high CPU when websocket not connected --- proxy/pkg/server/api_ws.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/proxy/pkg/server/api_ws.go b/proxy/pkg/server/api_ws.go index 9a3992e1f..064c3c34c 100644 --- a/proxy/pkg/server/api_ws.go +++ b/proxy/pkg/server/api_ws.go @@ -65,8 +65,13 @@ func (ac *APIController) Shutdown() { } func (ac *APIController) startWSHandler() { + notConnectedBackoff := 1 for { if !ac.wsConn.IsConnected() { + notConnectedWait := time.Duration(notConnectedBackoff) * time.Second + ac.logger.WithField("loop", "ws-handler").WithField("wait", notConnectedWait).Info("Not connected loop") + time.Sleep(notConnectedWait) + notConnectedBackoff += notConnectedBackoff continue } var wsMsg websocketMessage @@ -76,9 +81,6 @@ func (ac *APIController) startWSHandler() { ac.wsConn.CloseAndReconnect() continue } - if wsMsg.Instruction != WebsocketInstructionAck { - ac.logger.Debugf("%+v\n", wsMsg) - } if wsMsg.Instruction == WebsocketInstructionTriggerUpdate { err := ac.UpdateIfRequired() if err != nil {