Skip to content

Commit

Permalink
Merge pull request #259 from OffchainLabs/fix-batch-response-error
Browse files Browse the repository at this point in the history
Fix error handling of batch pushResponse
  • Loading branch information
PlasmaPower authored Sep 28, 2023
2 parents 9ad66d6 + e0906bd commit 921163a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions rpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit 921163a

Please sign in to comment.