diff --git a/pkg/rpc/client/wsclient.go b/pkg/rpc/client/wsclient.go index 7ff486246..8a8e4824f 100644 --- a/pkg/rpc/client/wsclient.go +++ b/pkg/rpc/client/wsclient.go @@ -114,12 +114,15 @@ func (c *WSClient) Close() { func (c *WSClient) wsReader() { c.ws.SetReadLimit(wsReadLimit) - c.ws.SetPongHandler(func(string) error { c.ws.SetReadDeadline(time.Now().Add(wsPongLimit)); return nil }) + c.ws.SetPongHandler(func(string) error { return c.ws.SetReadDeadline(time.Now().Add(wsPongLimit)) }) readloop: for { rr := new(requestResponse) - c.ws.SetReadDeadline(time.Now().Add(wsPongLimit)) - err := c.ws.ReadJSON(rr) + err := c.ws.SetReadDeadline(time.Now().Add(wsPongLimit)) + if err != nil { + break + } + err = c.ws.ReadJSON(rr) if err != nil { // Timeout/connection loss/malformed response. break @@ -191,12 +194,16 @@ func (c *WSClient) wsWriter() { if !ok { return } - c.ws.SetWriteDeadline(time.Now().Add(c.opts.RequestTimeout)) + if err := c.ws.SetWriteDeadline(time.Now().Add(c.opts.RequestTimeout)); err != nil { + return + } if err := c.ws.WriteJSON(req); err != nil { return } case <-pingTicker.C: - c.ws.SetWriteDeadline(time.Now().Add(wsWriteLimit)) + if err := c.ws.SetWriteDeadline(time.Now().Add(wsWriteLimit)); err != nil { + return + } if err := c.ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil { return } diff --git a/pkg/rpc/server/server.go b/pkg/rpc/server/server.go index ab3e5bca7..085329474 100644 --- a/pkg/rpc/server/server.go +++ b/pkg/rpc/server/server.go @@ -359,7 +359,9 @@ eventloop: if !ok { break eventloop } - ws.SetWriteDeadline(time.Now().Add(wsWriteLimit)) + if err := ws.SetWriteDeadline(time.Now().Add(wsWriteLimit)); err != nil { + break eventloop + } if err := ws.WritePreparedMessage(event); err != nil { break eventloop } @@ -367,12 +369,16 @@ eventloop: if !ok { break eventloop } - ws.SetWriteDeadline(time.Now().Add(wsWriteLimit)) + if err := ws.SetWriteDeadline(time.Now().Add(wsWriteLimit)); err != nil { + break eventloop + } if err := ws.WriteJSON(res); err != nil { break eventloop } case <-pingTicker.C: - ws.SetWriteDeadline(time.Now().Add(wsWriteLimit)) + if err := ws.SetWriteDeadline(time.Now().Add(wsWriteLimit)); err != nil { + break eventloop + } if err := ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil { break eventloop } @@ -397,10 +403,10 @@ drainloop: func (s *Server) handleWsReads(ws *websocket.Conn, resChan chan<- response.AbstractResult, subscr *subscriber) { ws.SetReadLimit(wsReadLimit) - ws.SetReadDeadline(time.Now().Add(wsPongLimit)) - ws.SetPongHandler(func(string) error { ws.SetReadDeadline(time.Now().Add(wsPongLimit)); return nil }) + err := ws.SetReadDeadline(time.Now().Add(wsPongLimit)) + ws.SetPongHandler(func(string) error { return ws.SetReadDeadline(time.Now().Add(wsPongLimit)) }) requestloop: - for { + for err == nil { req := request.NewRequest() err := ws.ReadJSON(req) if err != nil {