Skip to content

Commit 4017efe

Browse files
authored
rpc: reject empty batch in BatchCallContext (ethereum#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.
1 parent 9f434c0 commit 4017efe

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

rpc/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ func (c *Client) BatchCall(b []BatchElem) error {
397397
//
398398
// Note that batch calls may not be executed atomically on the server side.
399399
func (c *Client) BatchCallContext(ctx context.Context, b []BatchElem) error {
400+
if len(b) == 0 {
401+
return &invalidRequestError{"empty batch"}
402+
}
400403
var (
401404
msgs = make([]*jsonrpcMessage, len(b))
402405
byID = make(map[string]int, len(b))

0 commit comments

Comments
 (0)