Skip to content

Commit 29e2861

Browse files
committed
f: fix arc count gap
1 parent c659e34 commit 29e2861

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
@@ -267,9 +267,11 @@ impl FilesystemStoreInner {
267267
let more_writes_pending = async_state.latest_written_version < async_state.latest_version;
268268

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

0 commit comments

Comments
 (0)