Skip to content

Commit 693abf8

Browse files
committed
Fix potential deadlock in file store MultiLastSeqs
Signed-off-by: Neil Twigg <[email protected]>
1 parent 2dc14f8 commit 693abf8

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

server/filestore.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3042,7 +3042,13 @@ func (fs *fileStore) SubjectsState(subject string) map[string]SimpleState {
30423042
func (fs *fileStore) AllLastSeqs() ([]uint64, error) {
30433043
fs.mu.RLock()
30443044
defer fs.mu.RUnlock()
3045+
return fs.allLastSeqsLocked()
3046+
}
30453047

3048+
// allLastSeqsLocked will return a sorted list of last sequences for all
3049+
// subjects, but won't take the lock to do it, to avoid the issue of compounding
3050+
// read locks causing a deadlock with a write lock.
3051+
func (fs *fileStore) allLastSeqsLocked() ([]uint64, error) {
30463052
if fs.state.Msgs == 0 || fs.noTrackSubjects() {
30473053
return nil, nil
30483054
}
@@ -3113,7 +3119,7 @@ func (fs *fileStore) MultiLastSeqs(filters []string, maxSeq uint64, maxAllowed i
31133119

31143120
// See if we can short circuit if we think they are asking for all last sequences and have no maxSeq or maxAllowed set.
31153121
if maxSeq == 0 && maxAllowed <= 0 && fs.filterIsAll(filters) {
3116-
return fs.AllLastSeqs()
3122+
return fs.allLastSeqsLocked()
31173123
}
31183124

31193125
lastBlkIndex := len(fs.blks) - 1

0 commit comments

Comments
 (0)