From 5061259f99600165ac0f45655c93bf1f6afea8f9 Mon Sep 17 00:00:00 2001 From: Tristan Wilson Date: Mon, 27 Feb 2023 21:52:30 -0800 Subject: [PATCH] Fix batchCallBuffer timeout handling --- rpc/handler.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rpc/handler.go b/rpc/handler.go index e16aa5e68..953d04f59 100644 --- a/rpc/handler.go +++ b/rpc/handler.go @@ -158,7 +158,14 @@ func (b *batchCallBuffer) timeout(ctx context.Context, conn jsonWriter) { for _, msg := range b.calls { if !msg.isNotification() { resp := msg.errorResponse(&internalServerError{errcodeTimeout, errMsgTimeout}) - b.resp = append(b.resp, resp) + serialized, err := json.Marshal(resp) + if err != nil { + conn.writeJSON(ctx, errorMessage(&parseError{"error serializing timeout error: " + err.Error()}), true) + b.wrote = true + return + } + + b.resp = append(b.resp, serialized) } } b.doWrite(ctx, conn, true) @@ -243,7 +250,7 @@ func (h *handler) handleBatch(msgs []*jsonrpcMessage) { resp := h.handleCallMsg(cp, msg) err := callBuffer.pushResponse(resp) if err != nil { - h.conn.writeJSON(cp.ctx, errorMessage(err)) + h.conn.writeJSON(cp.ctx, errorMessage(err), true) return } }