fix(jsonrpc): recover from panic in handleRequest - #4040
Open
Lepsina wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
🟢 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/recoverwrapper aroundServer.handleRequestto convert panics into-32603 Internal errorresponses (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.
| s.logger.Error("Recovered from panic while handling RPC request", | ||
| zap.String("method", req.Method), | ||
| zap.Any("panic", r), | ||
| zap.ByteString("stack", debug.Stack()), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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