Skip to content

Commit 7b46ffb

Browse files
committed
f: fix arc count gap
1 parent a047b05 commit 7b46ffb

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lightning-persister/src/fs_store.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,11 @@ impl FilesystemStoreInner {
268268
let more_writes_pending = async_state.latest_written_version < async_state.latest_version;
269269

270270
// If there are no more writes pending and no arcs in use elsewhere, we can remove the map entry to prevent
271-
// leaking memory. The two arcs are the one in the map and the one held here in inner_lock_ref.
271+
// leaking memory. The two arcs are the one in the map and the one held here in inner_lock_ref. The outer lock
272+
// is obtained first, to avoid a new arc being cloned after we've already counted.
273+
let mut outer_lock = self.locks.lock().unwrap();
272274
if !more_writes_pending && Arc::strong_count(&inner_lock_ref) == 2 {
273-
self.locks.lock().unwrap().remove(&dest_file_path);
275+
outer_lock.remove(&dest_file_path);
274276
}
275277
}
276278

0 commit comments

Comments
 (0)