Skip to content

jsonrpc: panics in RPC handlers/validators crash the connection or vanish silently in batch requests #4039

Description

@Lepsina

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.

  1. 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.
  2. 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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions