From 4a67c7872cccd7e59f1177dd775c1b8fa07f5096 Mon Sep 17 00:00:00 2001 From: Jose Garcia Date: Thu, 25 Nov 2021 16:30:23 +0000 Subject: [PATCH] Guard against nil handlers --- jsonrpc2.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/jsonrpc2.go b/jsonrpc2.go index 7815c84..2423893 100644 --- a/jsonrpc2.go +++ b/jsonrpc2.go @@ -355,6 +355,7 @@ func (id *ID) UnmarshalJSON(data []byte) error { type Conn struct { stream ObjectStream + // If Handler is nil, incoming requests are skipped h Handler mu sync.Mutex @@ -620,7 +621,11 @@ func (c *Conn) readMessages(ctx context.Context) { for _, onRecv := range c.onRecv { onRecv(m.request, nil) } - c.h.Handle(ctx, c, m.request) + + // If handler is not nil, handle the request. + if c.h != nil { + c.h.Handle(ctx, c, m.request) + } case m.response != nil: resp := m.response