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.
This commit is contained in:
rayoo 2026-05-28 16:38:34 +08:00 committed by GitHub
parent 9f434c04db
commit 4017efe345
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -397,6 +397,9 @@ func (c *Client) BatchCall(b []BatchElem) error {
// //
// Note that batch calls may not be executed atomically on the server side. // Note that batch calls may not be executed atomically on the server side.
func (c *Client) BatchCallContext(ctx context.Context, b []BatchElem) error { func (c *Client) BatchCallContext(ctx context.Context, b []BatchElem) error {
if len(b) == 0 {
return &invalidRequestError{"empty batch"}
}
var ( var (
msgs = make([]*jsonrpcMessage, len(b)) msgs = make([]*jsonrpcMessage, len(b))
byID = make(map[string]int, len(b)) byID = make(map[string]int, len(b))