From 7e3e54f55ecf644698502037bd413f5c0117ad6d Mon Sep 17 00:00:00 2001 From: Piotr Piotrowski Date: Tue, 12 Sep 2023 16:24:25 +0200 Subject: [PATCH] [FIXED] Nil pointer when sub is nil in service API err handler (#1371) Signed-off-by: Piotr Piotrowski --- micro/service.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/micro/service.go b/micro/service.go index cee4ef3af..5d2dd3656 100644 --- a/micro/service.go +++ b/micro/service.go @@ -474,6 +474,10 @@ func (s *service) wrapConnectionEventCallbacks() { s.natsHandlers.asyncErr = s.nc.ErrorHandler() if s.natsHandlers.asyncErr != nil { s.nc.SetErrorHandler(func(c *nats.Conn, sub *nats.Subscription, err error) { + if sub == nil { + s.natsHandlers.asyncErr(c, sub, err) + return + } endpoint, match := s.matchSubscriptionSubject(sub.Subject) if !match { s.natsHandlers.asyncErr(c, sub, err) @@ -496,6 +500,9 @@ func (s *service) wrapConnectionEventCallbacks() { }) } else { s.nc.SetErrorHandler(func(c *nats.Conn, sub *nats.Subscription, err error) { + if sub == nil { + return + } endpoint, match := s.matchSubscriptionSubject(sub.Subject) if !match { return