diff --git a/server/stream.go b/server/stream.go index f8fb6d58dd9..1c2a259fa72 100644 --- a/server/stream.go +++ b/server/stream.go @@ -3149,7 +3149,6 @@ func (mset *stream) setupMirrorConsumer() error { } mirror := mset.mirror - mirrorWg := &mirror.wg // We want to throttle here in terms of how fast we request new consumers, // or if the previous is still in progress. @@ -3308,7 +3307,16 @@ func (mset *stream) setupMirrorConsumer() error { // Wait for previous processMirrorMsgs go routine to be completely done. // If none is running, this will not block. - mirrorWg.Wait() + mset.mu.Lock() + if mset.mirror == nil { + // Mirror config has been removed. + mset.mu.Unlock() + return + } else { + wg := &mset.mirror.wg + mset.mu.Unlock() + wg.Wait() + } select { case ccr := <-respCh: