Skip to content

Commit

Permalink
Fix panic when defining function during shutdown
Browse files Browse the repository at this point in the history
This fixes a race condition that can happen when the VM is shutting down
where our call to `napi::create_function` succeeds but then our
subsequent call to `napi::add_finalizer` fails, causing a panic. We need
to let this specific failure mode slide to avoid crashing.
  • Loading branch information
rf- committed Oct 31, 2022
1 parent 616e5f1 commit 2bf1525
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion crates/neon/src/sys/fun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ where
// If adding the finalizer fails the closure will leak, but it would
// be unsafe to drop it because there's no guarantee V8 won't use the
// pointer.
assert_eq!(status, napi::Status::Ok);
//
// As a special case, we also allow PendingException, because it means
// we're shutting down the VM and don't need to worry about cleanup.
assert!(matches!(
status,
napi::Status::Ok | napi::Status::PendingException
));
}

Ok(out)
Expand Down

0 comments on commit 2bf1525

Please sign in to comment.