From fc20e833ca6319da8c553c2a49502068efab3949 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 15 Apr 2021 09:05:48 -0700 Subject: [PATCH] src: fix finalization crash PR-URL: https://github.com/nodejs/node/pull/38250 Fixes: https://github.com/nodejs/node/issues/38040 Reviewed-By: Beth Griggs Reviewed-By: Antoine du Hamel --- src/js_native_api_v8.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc index 664aa2d41bbc98..54bcf2e9715a0a 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -372,6 +372,9 @@ class Reference : public RefBase { protected: inline void Finalize(bool is_env_teardown = false) override { + if (is_env_teardown) env_teardown_finalize_started_ = true; + if (!is_env_teardown && env_teardown_finalize_started_) return; + // During env teardown, `~napi_env()` alone is responsible for finalizing. // Thus, we don't want any stray gc passes to trigger a second call to // `Finalize()`, so let's reset the persistent here if nothing is @@ -405,6 +408,7 @@ class Reference : public RefBase { data.GetParameter()->Finalize(); } + bool env_teardown_finalize_started_ = false; v8impl::Persistent _persistent; };