Skip to content

Commit

Permalink
Fix datarace in filestore calling tombs().
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Collison <derek@nats.io>
  • Loading branch information
derekcollison authored and wallyqs committed Dec 9, 2024
1 parent 192f48b commit 5a986d1
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions server/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -7565,16 +7565,22 @@ func (fs *fileStore) reset() error {
}

// Return all active tombstones in this msgBlock.
// Write lock should be held.
func (mb *msgBlock) tombs() []msgId {
var tombs []msgId
mb.mu.Lock()
defer mb.mu.Unlock()
return mb.tombsLocked()
}

if !mb.cacheAlreadyLoaded() {
// Return all active tombstones in this msgBlock.
// Write lock should be held.
func (mb *msgBlock) tombsLocked() []msgId {
if mb.cacheNotLoaded() {
if err := mb.loadMsgsWithLock(); err != nil {
return nil
}
}

var tombs []msgId
var le = binary.LittleEndian
buf := mb.cache.buf

Expand Down Expand Up @@ -7655,7 +7661,7 @@ func (fs *fileStore) Truncate(seq uint64) error {
for mb := getLastMsgBlock(); mb != nlmb; mb = getLastMsgBlock() {
mb.mu.Lock()
// We do this to load tombs.
tombs = append(tombs, mb.tombs()...)
tombs = append(tombs, mb.tombsLocked()...)
purged += mb.msgs
bytes += mb.bytes
fs.removeMsgBlock(mb)
Expand Down

0 comments on commit 5a986d1

Please sign in to comment.