[ws-server] reset readTimeout when we receive something

This commit is contained in:
Anton Kaliaev 2017-08-08 16:03:04 -04:00
parent 8267920749
commit 9b5f21a650
No known key found for this signature in database
GPG Key ID: 7B6881D965918214
1 changed files with 7 additions and 3 deletions

View File

@ -502,12 +502,16 @@ func (wsc *wsConnection) readRoutine() {
// We use `readTimeout` to handle read timeouts.
_, in, err := wsc.baseConn.ReadMessage()
if err != nil {
wsc.Logger.Info("Failed to read from connection", "remote", wsc.remoteAddr, "err", err.Error())
// an error reading the connection,
// kill the connection
if websocket.IsCloseError(err, websocket.CloseNormalClosure) {
wsc.Logger.Info("Client closed the connection", "remote", wsc.remoteAddr)
} else {
wsc.Logger.Info("Failed to read from connection", "remote", wsc.remoteAddr, "err", err.Error())
}
wsc.Stop()
return
}
wsc.readTimeout.Reset(wsc.pongWait)
var request types.RPCRequest
err = json.Unmarshal(in, &request)
if err != nil {