From f86c12cb98f86ca41a2ae32ac63e308f83c1ffb4 Mon Sep 17 00:00:00 2001 From: rayoo Date: Thu, 28 May 2026 16:38:34 +0800 Subject: [PATCH] rpc: reject empty batch in BatchCallContext (#34985) The server already rejects empty batches with -32600. On the client side, calling BatchCallContext with a zero-length slice on inproc/WS/IPC transports registers no request IDs but the server still replies with an error message whose id is null. The dispatch loop has no requestOp to match it to, so op.resp is never written and op.wait blocks until ctx deadline. Short-circuit on len(b) == 0 with the same invalidRequestError the server uses, so all transports return immediately with -32600. --- rpc/client.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rpc/client.go b/rpc/client.go index 06e3fb6047..0f8146a8aa 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -398,6 +398,9 @@ func (c *Client) BatchCall(b []BatchElem) error { // // Note that batch calls may not be executed atomically on the server side. func (c *Client) BatchCallContext(ctx context.Context, b []BatchElem) error { + if len(b) == 0 { + return &invalidRequestError{"empty batch"} + } var ( msgs = make([]*jsonrpcMessage, len(b)) byID = make(map[string]int, len(b))