mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-22 17:31:34 +00:00
recover from panic in WS JSON RPC readRoutine
https://github.com/tendermint/tendermint/pull/724#issuecomment-335316484
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"runtime/debug"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -486,7 +487,17 @@ func (wsc *wsConnection) TryWriteRPCResponse(resp types.RPCResponse) bool {
|
|||||||
// Read from the socket and subscribe to or unsubscribe from events
|
// Read from the socket and subscribe to or unsubscribe from events
|
||||||
func (wsc *wsConnection) readRoutine() {
|
func (wsc *wsConnection) readRoutine() {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
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.Close()
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
wsc.baseConn.SetPongHandler(func(m string) error {
|
wsc.baseConn.SetPongHandler(func(m string) error {
|
||||||
|
Reference in New Issue
Block a user