Skip to content

fix(jsonrpc): recover from panic in handleRequest - #4040

Open
Lepsina wants to merge 1 commit into
NethermindEth:mainfrom
Lepsina:fix/rpc-panic-recovery
Open

fix(jsonrpc): recover from panic in handleRequest#4040
Lepsina wants to merge 1 commit into
NethermindEth:mainfrom
Lepsina:fix/rpc-panic-recovery

Conversation

@Lepsina

@Lepsina Lepsina commented Sep 5, 2026

Copy link
Copy Markdown

This adds a defer/recover around handleRequest that converts any panic into a JSON-RPC Internal error (-32603), covering both the handler call and buildArguments/validator paths. Notification requests (no id) still get no response on panic.

issue: #4039

Copilot AI lite review requested due to automatic review settings September 5, 2026 08:30
@Lepsina Lepsina changed the title recover from panic in handleRequest fix(jsonrpc): recover from panic in handleRequest Sep 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The panic recovery logic and added tests appear to satisfy the issue’s acceptance criteria, with only a minor logging-format improvement suggested.

Pull request overview

This PR hardens the JSON-RPC server against panics originating from RPC handlers and parameter validation, ensuring panics become JSON-RPC Internal error responses instead of crashing or disappearing—addressing issue #4039’s acceptance criteria for both single and batch requests (and preserving notification no-response semantics).

Changes:

  • Add a defer/recover wrapper around Server.handleRequest to convert panics into -32603 Internal error responses (or no response for notifications), while logging the panic and stack.
  • Extend tests to cover handler panics, validator panics, notification behavior, and mixed batch behavior.
File summaries
File Description
jsonrpc/server.go Adds panic recovery in handleRequest and logs panic details while returning Internal error responses appropriately.
jsonrpc/server_test.go Adds regression tests for handler/validator panics (single, notification, and batch-mixed cases).
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread jsonrpc/server.go
s.logger.Error("Recovered from panic while handling RPC request",
zap.String("method", req.Method),
zap.Any("panic", r),
zap.ByteString("stack", debug.Stack()),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants