rpc: fix errcheck warnings in websocket code

This commit is contained in:
Roman Khimov 2021-05-12 21:45:32 +03:00
parent e9cefc4bfc
commit a44376903a
2 changed files with 24 additions and 11 deletions

View file

@ -114,12 +114,15 @@ func (c *WSClient) Close() {
func (c *WSClient) wsReader() { func (c *WSClient) wsReader() {
c.ws.SetReadLimit(wsReadLimit) 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: readloop:
for { for {
rr := new(requestResponse) rr := new(requestResponse)
c.ws.SetReadDeadline(time.Now().Add(wsPongLimit)) err := c.ws.SetReadDeadline(time.Now().Add(wsPongLimit))
err := c.ws.ReadJSON(rr) if err != nil {
break
}
err = c.ws.ReadJSON(rr)
if err != nil { if err != nil {
// Timeout/connection loss/malformed response. // Timeout/connection loss/malformed response.
break break
@ -191,12 +194,16 @@ func (c *WSClient) wsWriter() {
if !ok { if !ok {
return 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 { if err := c.ws.WriteJSON(req); err != nil {
return return
} }
case <-pingTicker.C: 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 { if err := c.ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
return return
} }

View file

@ -359,7 +359,9 @@ eventloop:
if !ok { if !ok {
break eventloop 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 { if err := ws.WritePreparedMessage(event); err != nil {
break eventloop break eventloop
} }
@ -367,12 +369,16 @@ eventloop:
if !ok { if !ok {
break eventloop 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 { if err := ws.WriteJSON(res); err != nil {
break eventloop break eventloop
} }
case <-pingTicker.C: 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 { if err := ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
break eventloop break eventloop
} }
@ -397,10 +403,10 @@ drainloop:
func (s *Server) handleWsReads(ws *websocket.Conn, resChan chan<- response.AbstractResult, subscr *subscriber) { func (s *Server) handleWsReads(ws *websocket.Conn, resChan chan<- response.AbstractResult, subscr *subscriber) {
ws.SetReadLimit(wsReadLimit) ws.SetReadLimit(wsReadLimit)
ws.SetReadDeadline(time.Now().Add(wsPongLimit)) err := ws.SetReadDeadline(time.Now().Add(wsPongLimit))
ws.SetPongHandler(func(string) error { ws.SetReadDeadline(time.Now().Add(wsPongLimit)); return nil }) ws.SetPongHandler(func(string) error { return ws.SetReadDeadline(time.Now().Add(wsPongLimit)) })
requestloop: requestloop:
for { for err == nil {
req := request.NewRequest() req := request.NewRequest()
err := ws.ReadJSON(req) err := ws.ReadJSON(req)
if err != nil { if err != nil {