From 06628de5fef7d3b10d3f913622d8bf23281e8016 Mon Sep 17 00:00:00 2001 From: Piotr Piotrowski Date: Sun, 12 Jan 2025 21:14:21 +0100 Subject: [PATCH] [FIXED] Protect against potential panics Signed-off-by: Piotr Piotrowski --- jetstream/jetstream.go | 2 +- nats.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jetstream/jetstream.go b/jetstream/jetstream.go index 3b94146dc..7099271ef 100644 --- a/jetstream/jetstream.go +++ b/jetstream/jetstream.go @@ -901,7 +901,7 @@ func (js *jetStream) StreamNames(ctx context.Context, opts ...StreamListOpt) Str for _, opt := range opts { if err := opt(&streamsReq); err != nil { l.err = err - close(l.streams) + close(l.names) return l } } diff --git a/nats.go b/nats.go index 0240fc54d..95d61a125 100644 --- a/nats.go +++ b/nats.go @@ -4685,14 +4685,14 @@ func (s *Subscription) Unsubscribe() error { // checkDrained will watch for a subscription to be fully drained // and then remove it. func (nc *Conn) checkDrained(sub *Subscription) { + if nc == nil || sub == nil { + return + } defer func() { sub.mu.Lock() defer sub.mu.Unlock() sub.draining = false }() - if nc == nil || sub == nil { - return - } // This allows us to know that whatever we have in the client pending // is correct and the server will not send additional information.