Description
jsonrpc.Server.handleRequest does not recover from panics raised by RPC method handlers or by parameter validators (s.validator.Struct(...), called from buildArguments/validateParam). There's already a TODO in the code:
// TODO: add recover() to catch panics from handlers/validators and return a JSON-RPC internal error
// instead of crashing the HTTP connection
There is a problem with both a single request and a batch request.
- Single (non-batch) request: handleRequest runs directly in the HTTP/WebSocket connection's goroutine. An unrecovered panic propagates up to net/http's own recover and terminates that one connection. With logs but without valid JSON-RPC response is returned to the client.
- Batch request: each element is processed via s.pool.Go(...). handleBatchRequest never calls s.pool.Wait(), so a panic is silently swallowed: the panicking element's response is simply missing from the batch array, with no error and nothing in the logs
Acceptance criteria
- A panic raised inside an RPC method create JSON-RPC Internal error response instead of crashing the connection.
- A panic raised during validateParams is recovered the same way.
- For notification requests per the JSON-RPC 2.0 spec it should still be logged, just not answered.
- A panic in one element of a batch response must show up as an Internal error for that element, while the rest of the batch completes normally.
Documentation link(s)
Description
jsonrpc.Server.handleRequest does not recover from panics raised by RPC method handlers or by parameter validators (s.validator.Struct(...), called from buildArguments/validateParam). There's already a TODO in the code:
// TODO: add recover() to catch panics from handlers/validators and return a JSON-RPC internal error
// instead of crashing the HTTP connection
There is a problem with both a single request and a batch request.
Acceptance criteria
Documentation link(s)