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.
This commit is contained in:
Bernhard B
2021-10-10 22:37:16 +02:00
parent 094e42059d
commit 795b4c3f99

View File

@@ -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
}