Skip to content

Commit c8f8a7b

Browse files
authored
fix(graph): make barrier more robust (#474)
1 parent 085c61e commit c8f8a7b

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

crates/graph/lib.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -418,18 +418,21 @@ impl EszipDataSection {
418418
pub async fn read_data_section_all(self: Arc<Self>) -> Result<(), ParseError> {
419419
// NOTE: Below codes is roughly originated from eszip@0.72.2/src/v2.rs
420420

421-
let this = {
422-
let sem = self.read_all_barrier.clone();
421+
let sem = self.read_all_barrier.clone();
422+
let this = loop {
423423
let permit = sem
424424
.acquire_many(READ_ALL_BARRIER_MAX_PERMITS as u32)
425425
.await
426426
.unwrap();
427427

428-
let this = Arc::into_inner(self).unwrap();
429-
430-
sem.close();
431-
drop(permit);
432-
this
428+
if Arc::strong_count(&self) != 1 {
429+
drop(permit);
430+
tokio::task::yield_now().await;
431+
continue;
432+
} else {
433+
sem.close();
434+
break Arc::into_inner(self).unwrap();
435+
}
433436
};
434437

435438
let modules = this.modules;

0 commit comments

Comments
 (0)