Skip to content

Commit

Permalink
fix(napi): don't hold on to borrow during iteration (denoland#17461)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bartlomieju committed Jan 18, 2023
1 parent 69ec45e commit f1b275e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ext/napi/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f1b275e

Please sign in to comment.