Fix possible deadlock on dataloss

Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
Derek Collison
2023-01-30 19:10:19 -08:00
parent e7d7313640
commit 598e27243f

View File

@@ -2429,7 +2429,8 @@ func (fs *fileStore) removeMsg(seq uint64, secure, needFSLock bool) (bool, error
if secure {
if ld, _ := mb.flushPendingMsgsLocked(); ld != nil {
fs.rebuildStateLocked(ld)
// We have the mb lock here, this needs the mb locks so do in its own go routine.
go fs.rebuildState(ld)
}
}
// Check if we need to write the index file and we are flush in place (fip).
@@ -3304,7 +3305,8 @@ func (mb *msgBlock) writeMsgRecord(rl, seq uint64, subj string, mhdr, msg []byte
if flush || werr != nil {
ld, err := mb.flushPendingMsgsLocked()
if ld != nil && mb.fs != nil {
mb.fs.rebuildStateLocked(ld)
// We have the mb lock here, this needs the mb locks so do in its own go routine.
go mb.fs.rebuildState(ld)
}
if err != nil {
return err