summaryrefslogtreecommitdiff
path: root/ext/napi/lib.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-01-18 02:14:53 +0100
committerGitHub <noreply@github.com>2023-01-18 02:14:53 +0100
commitf1b275ed6bd6dd1fc1eda8efa3816998ac0a5471 (patch)
treeddc046389f6d19235dd64e63d0f20893a86bcdc7 /ext/napi/lib.rs
parent69ec45eac76c63ea973c68479ea4f0bbf58b29e9 (diff)
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.
Diffstat (limited to 'ext/napi/lib.rs')
-rw-r--r--ext/napi/lib.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/ext/napi/lib.rs b/ext/napi/lib.rs
index 1cb1b7c26..a304a8818 100644
--- a/ext/napi/lib.rs
+++ b/ext/napi/lib.rs
@@ -533,7 +533,8 @@ pub fn init<P: NapiPermissions + 'static>(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;