Summary
A panicking handler currently propagates the panic up through handleRequests, crashing the goroutine and tearing down the connection ungracefully. The peer receives no response and no error — the connection simply closes.
Add panic recovery so a panicking handler is converted into an InternalError response (for requests) or silently discarded (for notifications), keeping the connection alive.
Proposed behaviour
- Recover the panic inside the per-request goroutine in
handleRequests
- For requests (non-nil ID): reply with
NewError(InternalError, ..., nil)
- For notifications (nil ID): discard silently — no response is expected
- Log the recovered panic value via the configured
Logger if present
Motivation
- A single misbehaving handler should not take down the entire connection
- Brings parity with
github.com/creachadair/jrpc2 and github.com/AdamSLevy/jsonrpc2
- Safer in production where handler panics (e.g. nil pointer) are hard to rule out entirely
Summary
A panicking handler currently propagates the panic up through
handleRequests, crashing the goroutine and tearing down the connection ungracefully. The peer receives no response and no error — the connection simply closes.Add panic recovery so a panicking handler is converted into an
InternalErrorresponse (for requests) or silently discarded (for notifications), keeping the connection alive.Proposed behaviour
handleRequestsNewError(InternalError, ..., nil)Loggerif presentMotivation
github.com/creachadair/jrpc2andgithub.com/AdamSLevy/jsonrpc2