From e0906bd9425a67ba156a599c9a6eac17a8e3ccd1 Mon Sep 17 00:00:00 2001 From: Lee Bousfield Date: Thu, 28 Sep 2023 15:38:27 -0600 Subject: [PATCH] Fix error handling of batch pushResponse --- rpc/handler.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/rpc/handler.go b/rpc/handler.go index 965344d8be..5c66928a08 100644 --- a/rpc/handler.go +++ b/rpc/handler.go @@ -152,15 +152,19 @@ func (b *batchCallBuffer) write(ctx context.Context, conn jsonWriter) { // timeout sends the responses added so far. For the remaining unanswered call // messages, it sends a timeout error response. func (b *batchCallBuffer) timeout(ctx context.Context, conn jsonWriter) { + b.respondWithError(ctx, conn, &internalServerError{errcodeTimeout, errMsgTimeout}) +} + +func (b *batchCallBuffer) respondWithError(ctx context.Context, conn jsonWriter, err error) { b.mutex.Lock() defer b.mutex.Unlock() for _, msg := range b.calls { if !msg.isNotification() { - resp := msg.errorResponse(&internalServerError{errcodeTimeout, errMsgTimeout}) + resp := msg.errorResponse(err) serialized, err := json.Marshal(resp) if err != nil { - conn.writeJSON(ctx, errorMessage(&parseError{"error serializing timeout error: " + err.Error()}), true) + conn.writeJSON(ctx, errorMessage(&parseError{"error serializing response error: " + err.Error()}), true) b.wrote = true return } @@ -237,7 +241,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), true) + callBuffer.respondWithError(cp.ctx, h.conn, err) return } }