From c8f8a7b3395a904bef7ac1d44028d8f1b809829b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=83=A5=EB=83=90=EC=B1=A0?= Date: Wed, 15 Jan 2025 12:04:12 +0900 Subject: [PATCH] fix(graph): make barrier more robust (#474) --- crates/graph/lib.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/graph/lib.rs b/crates/graph/lib.rs index fcdad91a..8ba04eba 100644 --- a/crates/graph/lib.rs +++ b/crates/graph/lib.rs @@ -418,18 +418,21 @@ impl EszipDataSection { pub async fn read_data_section_all(self: Arc) -> Result<(), ParseError> { // NOTE: Below codes is roughly originated from eszip@0.72.2/src/v2.rs - let this = { - let sem = self.read_all_barrier.clone(); + let sem = self.read_all_barrier.clone(); + let this = loop { let permit = sem .acquire_many(READ_ALL_BARRIER_MAX_PERMITS as u32) .await .unwrap(); - let this = Arc::into_inner(self).unwrap(); - - sem.close(); - drop(permit); - this + if Arc::strong_count(&self) != 1 { + drop(permit); + tokio::task::yield_now().await; + continue; + } else { + sem.close(); + break Arc::into_inner(self).unwrap(); + } }; let modules = this.modules;