Skip to content

Commit 407d8e5

Browse files
Fix deadlock on stream purge when consumer store returns error (#7546)
At the point that we enter `(*consumer).purge()`, the stream lock is already held. Therefore calling `mset.name()` on the error case deadlocks because it tries to acquire the stream lock again. Replaced with `mset.nameLocked(false)` so that we do not attempt to acquire the lock. Signed-off-by: Neil Twigg <[email protected]>
2 parents ed493ec + 01dcd62 commit 407d8e5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

server/consumer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5874,7 +5874,8 @@ func (o *consumer) hasNoLocalInterest() bool {
58745874

58755875
// This is when the underlying stream has been purged.
58765876
// sseq is the new first seq for the stream after purge.
5877-
// Lock should NOT be held.
5877+
// Consumer lock should NOT be held but the parent stream
5878+
// lock MUST be held.
58785879
func (o *consumer) purge(sseq uint64, slseq uint64, isWider bool) {
58795880
// Do not update our state unless we know we are the leader.
58805881
if !o.isLeader() {
@@ -5955,7 +5956,7 @@ func (o *consumer) purge(sseq uint64, slseq uint64, isWider bool) {
59555956
o.mu.Unlock()
59565957

59575958
if err := o.writeStoreState(); err != nil && s != nil && mset != nil {
5958-
s.Warnf("Consumer '%s > %s > %s' error on write store state from purge: %v", acc, mset.name(), name, err)
5959+
s.Warnf("Consumer '%s > %s > %s' error on write store state from purge: %v", acc, mset.nameLocked(false), name, err)
59595960
}
59605961
}
59615962

0 commit comments

Comments
 (0)