Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions locksordering.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@ clearObserverState so that they cannot interleave which would leave Raft nodes i
inconsistent observer states.

jscmMu -> Account -> jsAccount
jscmMu -> stream.clsMu
jscmMu -> RaftNode
jscmMu -> stream.clsMu
jscmMu -> RaftNode

The "clsMu" lock protects the consumer list on a stream, used for signalling consumer activity.

stream -> clsMu
8 changes: 6 additions & 2 deletions server/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"path/filepath"
"reflect"
"slices"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -2267,8 +2268,12 @@ func (mset *stream) purge(preq *JSApiStreamPurgeRequest) (purged uint64, err err
fseq = ss.First
}

// Take a copy of cList to avoid o.purge() potentially taking the stream lock and
// violating the lock ordering.
mset.clsMu.RLock()
for _, o := range mset.cList {
cList := slices.Clone(mset.cList)
mset.clsMu.RUnlock()
for _, o := range cList {
start := fseq
o.mu.RLock()
// we update consumer sequences if:
Expand All @@ -2290,7 +2295,6 @@ func (mset *stream) purge(preq *JSApiStreamPurgeRequest) (purged uint64, err err
o.purge(start, lseq, isWider)
}
}
mset.clsMu.RUnlock()

return purged, nil
}
Expand Down