Skip to content

Commit da42a46

Browse files
Gabriel Schulhoflegendecas
Gabriel Schulhof
andcommitted
node-api: force env shutdown deferring behavior
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 <[email protected]>
1 parent 2084f31 commit da42a46

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/js_native_api_v8.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ class RefBase : protected Finalizer, RefTracker {
270270

271271
protected:
272272
inline void Finalize(bool is_env_teardown = false) override {
273+
// Force deferring behavior if the finalizer happens to delete this
274+
// reference.
275+
if (is_env_teardown && RefCount() > 0) _refcount = 0;
276+
273277
if (_finalize_callback != nullptr) {
274278
_env->CallFinalizer(_finalize_callback, _finalize_data, _finalize_hint);
275279
}

0 commit comments

Comments
 (0)