Browse Source

recover from panic in WS JSON RPC readRoutine

https://github.com/tendermint/tendermint/pull/724#issuecomment-335316484
pull/724/head
Anton Kaliaev 7 years ago
parent
commit
d935a4f0a8
No known key found for this signature in database GPG Key ID: 7B6881D965918214
1 changed files with 12 additions and 1 deletions
  1. +12
    -1
      rpc/lib/server/handlers.go

+ 12
- 1
rpc/lib/server/handlers.go View File

@ -8,6 +8,7 @@ import (
"io/ioutil"
"net/http"
"reflect"
"runtime/debug"
"sort"
"strings"
"time"
@ -486,7 +487,17 @@ func (wsc *wsConnection) TryWriteRPCResponse(resp types.RPCResponse) bool {
// Read from the socket and subscribe to or unsubscribe from events
func (wsc *wsConnection) readRoutine() {
defer func() {
wsc.baseConn.Close()
if r := recover(); r != nil {
err, ok := r.(error)
if !ok {
err = fmt.Errorf("WSJSONRPC: %v", r)
}
wsc.Logger.Error("Panic in WSJSONRPC handler", "err", err, "stack", string(debug.Stack()))
wsc.WriteRPCResponse(types.RPCInternalError("unknown", err))
go wsc.readRoutine()
} else {
wsc.baseConn.Close()
}
}()
wsc.baseConn.SetPongHandler(func(m string) error {


Loading…
Cancel
Save