diff --git a/server/consumer.go b/server/consumer.go index 54bd3fd0..a04a57cf 100644 --- a/server/consumer.go +++ b/server/consumer.go @@ -2493,7 +2493,7 @@ func (o *consumer) infoWithSnap(snap bool) *ConsumerInfo { func (o *consumer) infoWithSnapAndReply(snap bool, reply string) *ConsumerInfo { o.mu.Lock() mset := o.mset - if mset == nil || mset.srv == nil { + if o.closed || mset == nil || mset.srv == nil { o.mu.Unlock() return nil } diff --git a/server/jetstream_api.go b/server/jetstream_api.go index dfade67d..6b32ffb4 100644 --- a/server/jetstream_api.go +++ b/server/jetstream_api.go @@ -4286,7 +4286,13 @@ func (s *Server) jsConsumerInfoRequest(sub *subscription, c *client, _ *Account, s.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp)) return } - resp.ConsumerInfo = obs.info() + + if resp.ConsumerInfo = obs.info(); resp.ConsumerInfo == nil { + // This consumer returned nil which means it's closed. Respond with not found. + resp.Error = NewJSConsumerNotFoundError() + s.sendAPIErrResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(&resp)) + return + } s.sendAPIResponse(ci, acc, subject, reply, string(msg), s.jsonResponse(resp)) }