From f1b275ed6bd6dd1fc1eda8efa3816998ac0a5471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 18 Jan 2023 02:14:53 +0100 Subject: [PATCH] fix(napi): don't hold on to borrow during iteration (#17461) I mistakenly held on to a RefCell's borrow for the whole time of iteration, but since these counters can be refed/unrefed from any thread that is a mistake. --- ext/napi/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/napi/lib.rs b/ext/napi/lib.rs index 1cb1b7c26b6b96..a304a8818767e8 100644 --- a/ext/napi/lib.rs +++ b/ext/napi/lib.rs @@ -533,7 +533,8 @@ pub fn init(unstable: bool) -> Extension { maybe_scheduling = true; } - for (_id, counter) in napi_state.tsfn_ref_counters.borrow().iter() { + let tsfn_ref_counters = napi_state.tsfn_ref_counters.borrow().clone(); + for (_id, counter) in tsfn_ref_counters.iter() { if counter.load(std::sync::atomic::Ordering::SeqCst) > 0 { maybe_scheduling = true; break;