From 795b4c3f997babb376cb2f075bd603a20ecbcc7b Mon Sep 17 00:00:00 2001 From: Bernhard B Date: Sun, 10 Oct 2021 22:37:16 +0200 Subject: [PATCH] Do not set any deadlines in websocket connection * The websocket rfc doesn't specify what to do when a client doesn't respond to a ping message. It just states that it must respond with a pong message. But it is unclear what should happen when the client doesn't respond with a pong message. So instead of closing the connection, we are keeping the connection open as long as possible. --- src/api/api.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/api/api.go b/src/api/api.go index fde1f89..dcc84ae 100644 --- a/src/api/api.go +++ b/src/api/api.go @@ -307,8 +307,7 @@ func (a *Api) handleSignalReceive(ws *websocket.Conn, number string) { func wsPong(ws *websocket.Conn) { ws.SetReadLimit(512) - ws.SetReadDeadline(time.Now().Add(pongWait)) - ws.SetPongHandler(func(string) error { ws.SetReadDeadline(time.Now().Add(pongWait)); return nil }) + ws.SetPongHandler(func(string) error { log.Debug("Received pong"); return nil }) for { _, _, err := ws.ReadMessage() if err != nil { @@ -322,7 +321,6 @@ func wsPing(ws *websocket.Conn) { for { select { case <-pingTicker.C: - ws.SetWriteDeadline(time.Now().Add(writeWait)) if err := ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil { return }