Skip to content

feat: panic recovery in handlers #41

Description

@mcriley821

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions