Skip to content

Commit

Permalink
node-api: force env shutdown deferring behavior
Browse files Browse the repository at this point in the history
The finalizer normally never gets called while a reference is strong.
However, during environment shutdown all finalizers must get called. In
order to unify the deferring behavior with that of a regular
finalization, we must force the reference to be weak when we call its
finalizer during environment shutdown.

Fixes: nodejs#37236
Co-authored-by: Chengzhong Wu <legendecas@gmail.com>
  • Loading branch information
2 people authored and gabrielschulhof committed Feb 18, 2021
1 parent 1c6484b commit 4cf6a26
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/js_native_api_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ class RefBase : protected Finalizer, RefTracker {

protected:
inline void Finalize(bool is_env_teardown = false) override {
// Force deferring behavior if the finalizer happens to delete this
// reference.
if (is_env_teardown && RefCount() > 0) _refcount = 0;

if (_finalize_callback != nullptr) {
_env->CallFinalizer(_finalize_callback, _finalize_data, _finalize_hint);
}
Expand Down

0 comments on commit 4cf6a26

Please sign in to comment.