jsonrpc: don't hang when remote crashes

This commit is contained in:
Łukasz Magiera 2019-07-18 13:26:09 +02:00
parent 6e24543e57
commit 185db76646

View File

@ -71,6 +71,24 @@ func handleWsConn(ctx context.Context, conn *websocket.Conn, handler handlers, r
handling := map[int64]context.CancelFunc{}
var handlingLk sync.Mutex
defer func() {
for id, req := range inflight {
req.ready <- clientResponse{
Jsonrpc: "2.0",
ID: id,
Error: &respError{
Message: "handler: websocket connection closed",
},
}
handlingLk.Lock()
for _, cancel := range handling {
cancel()
}
handlingLk.Unlock()
}
}()
cancelCtx := func(req frame) {
if req.ID != nil {
log.Warnf("%s call with ID set, won't respond", wsCancel)