Fix for panic in consumer, needed to recheck if consumer was closed

Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
Derek Collison
2023-09-15 08:40:21 -07:00
parent 8f84ea4224
commit f2e7ed91cb

View File

@@ -3794,7 +3794,9 @@ func (o *consumer) loopAndGatherMsgs(qch chan struct{}) {
sz int
wrn, wrb int
)
o.mu.Lock()
// consumer is closed when mset is set to nil.
if o.mset == nil {
o.mu.Unlock()
@@ -3817,6 +3819,13 @@ func (o *consumer) loopAndGatherMsgs(qch chan struct{}) {
// Grab our next msg.
pmsg, dc, err = o.getNextMsg()
// We can release the lock now under getNextMsg so need to check this condition again here.
// consumer is closed when mset is set to nil.
if o.mset == nil {
o.mu.Unlock()
return
}
// On error either wait or return.
if err != nil || pmsg == nil {
// On EOF we can optionally fast sync num pending state.