Skip to content

feat(async-worker): fix event-loop hang on env teardown - #1759

Open
dave-365 wants to merge 17 commits into
nodejs:mainfrom
dave-365:fix/async-worker-hot-reload
Open

dave-365 wants to merge 17 commits into
nodejs:mainfrom
dave-365:fix/async-worker-hot-reload

Conversation

@dave-365

@dave-365 dave-365 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor
image

@dave-365

dave-365 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Problem Background

Fixes: #1109

During application hot reload, pending AsyncProgressWorker operations can cause Node.js environment teardown issues, potentially resulting in event-loop hangs or application crashes.

This is particularly relevant to developers using node-addon-api in applications with hot-reload workflows.

Related discussion: [Issue #1109](#1109)

Proposed Solution

This PR introduces environment cleanup handling for AsyncProgressWorkerBase to ensure that pending asynchronous operations are properly handled during environment teardown.

The intention is to prevent event-loop hangs and improve application stability during hot reload.

Impact

This fix may benefit developers using AsyncProgressWorker in applications that frequently reload or recreate their Node.js environments.

Review Request

Could the maintainers please review the proposed cleanup approach and provide feedback on any lifecycle or thread-safety concerns?

@KevinEady

Copy link
Copy Markdown
Contributor

Hi @dave-365 ,

Is there any way to include a test in this PR? We have some tests already that check for various behavior in terminating environments, e.g. https://github.com/nodejs/node-addon-api/blob/main/test/error_terminating_environment.js . Maybe you can follow this pattern?

@dave-365

dave-365 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @dave-365 ,

Is there any way to include a test in this PR? We have some tests already that check for various behavior in terminating environments, e.g. https://github.com/nodejs/node-addon-api/blob/main/test/error_terminating_environment.js . Maybe you can follow this pattern?

@KevinEady Okay I will include test in this PR.

@dave-365

dave-365 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Hi @dave-365 ,

Is there any way to include a test in this PR? We have some tests already that check for various behavior in terminating environments, e.g. https://github.com/nodejs/node-addon-api/blob/main/test/error_terminating_environment.js . Maybe you can follow this pattern?

Hi @KevinEady

I have addressed the review feedback and added automated tests following the pattern in test/error_terminating_environment.js:

  1. Automated Test Coverage: Added test/async_progress_worker_terminating_environment.js testing both:
    • Environment termination while the worker thread is actively executing and sending progress.
    • Normal completion prior to environment teardown (verifying cleanup hook removal and no use-after-free).
    • Both scenarios are tested against C++ exceptions (binding.node) and no-exceptions (binding_noexcept.node) configurations.
  2. Lifecycle & UAF Prevention:
    • In ~AsyncProgressWorkerBase(), _cleanup_hook.Remove(Env()) safely removes the hook when the worker completes normally.
    • If OnEnvironmentTeardown() runs, _cleanup_hook is reset to empty to avoid duplicate removal.
    • If the environment is terminating, status is marked napi_cancelled so JavaScript callbacks (OnOK/OnError) are skipped during teardown, cleanly routing to destruction.
  3. Linting and Full Test Suite: All tests pass (node test), and formatting complies with clang-format and eslint.

@codecov-commenter

codecov-commenter commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.20%. Comparing base (534094b) to head (ae74630).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
napi-inl.h 71.42% 2 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1759      +/-   ##
==========================================
- Coverage   63.64%   63.20%   -0.44%     
==========================================
  Files           3        3              
  Lines        2071     2090      +19     
  Branches      738      753      +15     
==========================================
+ Hits         1318     1321       +3     
- Misses        161      166       +5     
- Partials      592      603      +11     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dave-365

dave-365 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

"Hi @KevinEady , I have pushed a fix for the Windows CI failure in commit f4d293c (properly awaiting worker termination and removing script evaluation from the finalizer). Could you please approve the workflow run when you have a moment? Thank you!"

@KevinEady

Copy link
Copy Markdown
Contributor

Not sure if the failure was due to the code, since it looks like it was failing while building, but re-ran anyway

@dave-365

dave-365 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Not sure if the failure was due to the code, since it looks like it was failing while building, but re-ran anyway
@KevinEady Thought it was building issue failed now again Unix failed I will check on local.

@dave-365

dave-365 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

@KevinEady
image
the test case was execution times was low for that window that is the root causse in the test file i fixed and i tested fully download visual studio in local now it's npm run pretest working fix no error.
Could you please approve the workflow run when you have a moment? Thank you!"

@KevinEady

KevinEady commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Hi @dave-365 , the CI failures was due to some PGO thing. This was fixed in main via 61fbf12 ... If you rebase to main, you'll get this fix in.

dave-365 and others added 4 commits November 8, 2026 10:38
…clean hool after free and no use, test afainst cpp bingidn noe and nodeexcept and onenvi tear down duplicate remvoal and while terminative napi cancelled no call onOk and OnError function
@dave-365
dave-365 force-pushed the fix/async-worker-hot-reload branch from 8b08f6b to 86d9a07 Compare November 8, 2026 05:09
@dave-365

dave-365 commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Hi @dave-365 , the CI failures was due to some PGO thing. This was fixed in main via 61fbf12 ... If you rebase to main, you'll get this fix in.

@KevinEady I was rebased this branch and latest code pushed. Can you try now.

@dave-365

dave-365 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

@KevinEady can you proceed workflow run.

@dave-365

Copy link
Copy Markdown
Contributor Author

@KevinEady All checks passed now. If you any comments I fix that either can you proceed for merge.

Comment thread napi-inl.h Resolved
@dave-365

Copy link
Copy Markdown
Contributor Author

@KevinEady all the comments were fixed.

Comment thread napi-inl.h Resolved
@dave-365
dave-365 requested a review from KevinEady November 13, 2026 16:30
@dave-365

Copy link
Copy Markdown
Contributor Author

Hi @KevinEady Can you run workflow i was fixed everything and sorry for the delay i was sick.

@dave-365

dave-365 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

@KevinEady there was linux and unix check sum failed now I was added. now you can approve the workflow run.

@KevinEady Can you proceed. friendly reminder.

Comment thread napi-inl.h Resolved
Comment thread napi-inl.h Resolved
@dave-365

Copy link
Copy Markdown
Contributor Author

@KevinEady all the questions resolved and I fix the git check linux and unix double check failure can you approve workflow run.

@dave-365

Copy link
Copy Markdown
Contributor Author

@KevinEady I have fixed the git CI check issue Linux and UNIX platform so kindly approve the workflow run.

@KevinEady

Copy link
Copy Markdown
Contributor

@dave-365 why did you need to go back to the napi_call_function() implementation?

@dave-365

dave-365 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

@dave-365 why did you need to go back to the napi_call_function() implementation?

@KevinEady Yes I we need this due to linus and unix has double-release so premature destruction so it completely fails there. So apply and npm test local that's completely works fine without any error.

That's why my git ci fails so many times each time you apprve after that's why I apply this.

@dave-365

Copy link
Copy Markdown
Contributor Author

@dave-365 why did you need to go back to the napi_call_function() implementation?

@KevinEady Earlier we use that time git CI all check's passed.

@KevinEady

Copy link
Copy Markdown
Contributor

@dave-365 but why is it necessary? When is it the case that, within OnThreadSafeFunctionFinalize, that status != napi_cancelled but you cannot call into js (i.e. you get a napi_cannot_run_js?)

@dave-365

Copy link
Copy Markdown
Contributor Author

@dave-365 but why is it necessary? When is it the case that, within OnThreadSafeFunctionFinalize, that status != napi_cancelled but you cannot call into js (i.e. you get a napi_cannot_run_js?)

@KevinEady This happens when worker.terminate() is called and the worker finishes Execute() right as teardown begins:

worker.terminate() immediately puts the Environment / V8 Isolate into a terminating state where JS can no longer run (napi_cannot_run_js / napi_pending_exception), before Environment::RunCleanup() runs OnEnvironmentTeardown.

If OnWorkComplete -> _tsfn.Release() -> OnThreadSafeFunctionFinalize runs on the event loop before OnEnvironmentTeardown executes (or before our cleanup hook runs), _teardown_called is still false and _complete_status is napi_ok, so status != napi_cancelled.

Without probing via napi_call_function to downgrade status to napi_cancelled, AsyncWorker::OnWorkComplete attempts to run OnOK()/OnError() and call into JS on a terminating environment. (On a healthy environment, calling undefined returns napi_function_expected, leaving status untouched.)

@dave-365

Copy link
Copy Markdown
Contributor Author

@dave-365 but why is it necessary? When is it the case that, within OnThreadSafeFunctionFinalize, that status != napi_cancelled but you cannot call into js (i.e. you get a napi_cannot_run_js?)

@KevinEady This happens when worker.terminate() is called and the worker finishes Execute() right as teardown begins:

worker.terminate() immediately puts the Environment / V8 Isolate into a terminating state where JS can no longer run (napi_cannot_run_js / napi_pending_exception), before Environment::RunCleanup() runs OnEnvironmentTeardown.

If OnWorkComplete -> _tsfn.Release() -> OnThreadSafeFunctionFinalize runs on the event loop before OnEnvironmentTeardown executes (or before our cleanup hook runs), _teardown_called is still false and _complete_status is napi_ok, so status != napi_cancelled.

Without probing via napi_call_function to downgrade status to napi_cancelled, AsyncWorker::OnWorkComplete attempts to run OnOK()/OnError() and call into JS on a terminating environment. (On a healthy environment, calling undefined returns napi_function_expected, leaving status untouched.)

@KevinEady Can we proceed further ?

@KevinEady

Copy link
Copy Markdown
Contributor

@dave-365 I will need to discuss with the team, because technically the async worker did complete its work, so passing napi_cancelled to OnWorkComplete might not be correct behavior.

@dave-365

Copy link
Copy Markdown
Contributor Author

@dave-365 I will need to discuss with the team, because technically the async worker did complete its work, so passing napi_cancelled to OnWorkComplete might not be correct behavior.

@KevinEady Thanks, I am waiting for your response.

@KevinEady

Copy link
Copy Markdown
Contributor

Hi @dave-365 ,

We discussed this in the Node-API meeting on 27 Nov 2026.

Our consensus is that node-addon-api should not hide the fact that an add-on cannot call into JavaScript by passing napi_cancelled to the handlers.

Our idea is that:

  • AsyncWorker::OnWorkComplete will call the OnOK() or OnError() methods as-is, so remove your handling of passing napi_cancelled if cannot call into js.
    • Note that the construction of the Error passed to OnError() via Error::New() will call into JavaScript: if this fails, construct an empty error via Error() default constructor to pass to OnError().
  • The add-on writer themselves must handle the napi_cannot_call_into_js error inside their overridden OnOK() and OnError() methods. This allows them to understand that
  • The default node-addon-api of OnOK() and OnError() (which just calls the optionally-provided callback) will handle the napi_cannot_call_into_js as well, by not do anything.

Then, the Markdown documentation should be updated, stating that it is possible that OnOK() an OnError() can be called when the environment is terminating, with the Error passed to OnError() in a terminating environment will be empty (i.e. IsEmpty() == true).

Does this make sense to you?

@dave-365

Copy link
Copy Markdown
Contributor Author

Hi @dave-365 ,

We discussed this in the Node-API meeting on 27 Nov 2026.

Our consensus is that node-addon-api should not hide the fact that an add-on cannot call into JavaScript by passing napi_cancelled to the handlers.

Our idea is that:

  • AsyncWorker::OnWorkComplete will call the OnOK() or OnError() methods as-is, so remove your handling of passing napi_cancelled if cannot call into js.

    • Note that the construction of the Error passed to OnError() via Error::New() will call into JavaScript: if this fails, construct an empty error via Error() default constructor to pass to OnError().
  • The add-on writer themselves must handle the napi_cannot_call_into_js error inside their overridden OnOK() and OnError() methods. This allows them to understand that

  • The default node-addon-api of OnOK() and OnError() (which just calls the optionally-provided callback) will handle the napi_cannot_call_into_js as well, by not do anything.

Then, the Markdown documentation should be updated, stating that it is possible that OnOK() an OnError() can be called when the environment is terminating, with the Error passed to OnError() in a terminating environment will be empty (i.e. IsEmpty() == true).

Does this make sense to you?

@KevinEady Yes It's worked right now the double release checks pass without compromising onOk and onError. Can you proceed further.

@dave-365

dave-365 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@KevinEady Can you proceed for further merging process.

@dave-365

dave-365 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

@KevinEady Can you proceed for further merging process.

@KevinEady gentle reminder.

@KevinEady

KevinEady commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Hi @dave-365 ,

There is a crash when compiling against Node-API version 9:

npx node-gyp configure -C test -- -f ninja && export NAPI_VERSION=9 && ninja -C test/build/Debug && NODE_API_BUILD_CONFIG=Debug node test/async_progress_worker_terminating_environment.js
node:internal/process/promises:394
    triggerUncaughtException(err, true /* fromPromise */);
    ^

AssertionError [ERR_ASSERTION]: Test case /Users/kevin.eady/Projects/node-addon-api/test/build/Debug/binding_noexcept.node 0 failed with status null: FATAL ERROR: Error::ThrowAsJavaScriptException napi_throw
----- Native stack trace -----

 1: 0x104a02fbc node::OnFatalError(char const*, char const*) [/Users/kevin.eady/.nvm/versions/node/v24.18.0/bin/node]
 2: 0x1049b41ac napi_open_callback_scope [/Users/kevin.eady/.nvm/versions/node/v24.18.0/bin/node]
 3: 0x138ab5b00 Napi::Env::Undefined() const [/Users/kevin.eady/Projects/node-addon-api/test/build/Debug/binding_noexcept.node]
 4: 0x138ab4b70 Napi::Error::ThrowAsJavaScriptException() const [/Users/kevin.eady/Projects/node-addon-api/test/build/Debug/binding_noexcept.node]
 5: 0x138ac26e0 Napi::details::CallAsyncWorkerCallback(napi_env__*, napi_value__*, napi_value__*, unsigned long, napi_value__* const*) [/Users/kevin.eady/Projects/node-addon-api/test/build/Debug/binding_noexcept.node]
 6: 0x138ac0984 Napi::AsyncWorker::OnOK() [/Users/kevin.eady/Projects/node-addon-api/test/build/Debug/binding_noexcept.node]
 7: 0x138ac1878 Napi::AsyncWorker::OnWorkComplete(Napi::Env, napi_status)::'lambda'()::operator()() const [/Users/kevin.eady/Projects/node-addon-api/test/build/Debug/binding_noexcept.node]
 8: 0x138ac182c napi_value__* Napi::details::WrapCallback<Napi::AsyncWorker::OnWorkComplete(Napi::Env, napi_status)::'lambda'()>(napi_env__*, Napi::AsyncWorker::OnWorkComplete(Napi::Env, napi_status)::'lambda'()) [/Users/kevin.eady/Projects/node-addon-api/test/build/Debug/binding_noexcept.node]
 9: 0x138ac1600 Napi::AsyncWorker::OnWorkComplete(Napi::Env, napi_status) [/Users/kevin.eady/Projects/node-addon-api/test/build/Debug/binding_noexcept.node]
10: 0x138ac7090 Napi::AsyncProgressWorkerBase<void>::OnThreadSafeFunctionFinalize(Napi::Env, void*, Napi::AsyncProgressWorkerBase<void>*) [/Users/kevin.eady/Projects/node-addon-api/test/build/Debug/binding_noexcept.node]
11: 0x138ac7314 Napi::details::ThreadSafeFinalize<Napi::AsyncProgressWorkerBase<void>, void (*)(Napi::Env, void*, Napi::AsyncProgressWorkerBase<void>*), Napi::AsyncProgressWorkerBase<void>>::FinalizeFinalizeWrapperWithDataAndContext(napi_env__*, void*, void*) [/Users/kevin.eady/Projects/node-addon-api/test/build/Debug/binding_noexcept.node]
12: 0x1049b7740 void napi_env__::CallIntoModule<void node_napi_env__::CallFinalizer<false>(void (*)(napi_env__*, void*, void*), void*, void*)::'lambda'(napi_env__*)&, void node_napi_env__::CallbackIntoModule<false, void node_napi_env__::CallFinalizer<false>(void (*)(napi_env__*, void*, void*), void*, void*)::'lambda'(napi_env__*)>(void node_napi_env__::CallFinalizer<false>(void (*)(napi_env__*, void*, void*), void*, void*)::'lambda'(napi_env__*)&&)::'lambda'(napi_env__*, v8::Local<v8::Value>)>(void node_napi_env__::CallFinalizer<false>(void (*)(napi_env__*, void*, void*), void*, void*)::'lambda'(napi_env__*)&, void node_napi_env__::CallFinalizer<false>(void (*)(napi_env__*, void*, void*), void*, void*)::'lambda'(napi_env__*)&&) [/Users/kevin.eady/.nvm/versions/node/v24.18.0/bin/node]
13: 0x1049b7504 void node::Environment::CloseHandle<uv_handle_s, v8impl::(anonymous namespace)::ThreadSafeFunction::CloseHandlesAndMaybeDelete(bool)::'lambda'(uv_handle_s*)>(uv_handle_s*, v8impl::(anonymous namespace)::ThreadSafeFunction::CloseHandlesAndMaybeDelete(bool)::'lambda'(uv_handle_s*))::'lambda'(uv_handle_s*)::__invoke(uv_handle_s*) [/Users/kevin.eady/.nvm/versions/node/v24.18.0/bin/node]
14: 0x1058cce40 uv_run [/Users/kevin.eady/.nvm/versions/node/v24.18.0/bin/node]
15: 0x10497b258 node::Environment::CleanupHandles() [/Users/kevin.eady/.nvm/versions/node/v24.18.0/bin/node]
16: 0x10497b96c node::Environment::RunCleanup() [/Users/kevin.eady/.nvm/versions/node/v24.18.0/bin/node]
17: 0x1048e950c node::FreeEnvironment(node::Environment*) [/Users/kevin.eady/.nvm/versions/node/v24.18.0/bin/node]
18: 0x104b3440c node::worker::Worker::Run() [/Users/kevin.eady/.nvm/versions/node/v24.18.0/bin/node]
19: 0x104b38c24 node::worker::Worker::StartThread(v8::FunctionCallbackInfo<v8::Value> const&)::$_0::__invoke(void*) [/Users/kevin.eady/.nvm/versions/node/v24.18.0/bin/node]
20: 0x187737c58 _pthread_start [/usr/lib/system/libsystem_pthread.dylib]
21: 0x187732c1c thread_start [/usr/lib/system/libsystem_pthread.dylib]


null !== 0

    at test (/Users/kevin.eady/Projects/node-addon-api/test/async_progress_worker_terminating_environment.js:88:14)
    at wrapTest (/Users/kevin.eady/Projects/node-addon-api/test/async_progress_worker_terminating_environment.js:70:5) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: null,
  expected: 0,
  operator: 'strictEqual',
  diff: 'simple'
}

Node.js v24.18.0

I guess it's because you can't do this check for napi_cannot_run_js on Node-API <10

https://github.com/dave-365/node-addon-api/blob/e63b28aec6835b359a71adc90cee280213ba7f16/napi-inl.h#L5760-L5762

@KevinEady

KevinEady commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Hi @dave-365 ,

Another serious crash is if the worker calls SuppressDestruct(), outliving the finalization of its internal ThreadSafeFunction. The environment is then torn down while the worker object is still alive. Teardown touches the
ThreadSafeFunction.

I added this test case in cd3731a

AssertionError [ERR_ASSERTION]: Test case /home/runner/work/node-addon-api/node-addon-api/test/build/Release/binding.node 2 failed with status null: 

null !== 0

    at test (/home/runner/work/node-addon-api/node-addon-api/test/async_progress_worker_terminating_environment.js:107:14)
    at wrapTest (/home/runner/work/node-addon-api/node-addon-api/test/async_progress_worker_terminating_environment.js:88:5)
    at async /home/runner/work/node-addon-api/node-addon-api/test/index.js:155:5 {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: null,
  expected: 0,
  operator: 'strictEqual',
  diff: 'simple'
}

@KevinEady

Copy link
Copy Markdown
Contributor

Hi @dave-365 ,

Another finding: the env teardown hook is not really what solves the problem you mention. The fix really comes from handling the napi_cannot_call_js error within OnOK / OnError.

Check this diff, which incorporates your changes to OnOK / OnError handling napi_cannot_call_js and napi_pending_exception (for Node-API <10, done where status == napi_pending_exception but napi_is_exception_pending() is false.

diff --git a/napi-inl.h b/napi-inl.h
index 9424fd0..fc7b99a 100644
--- a/napi-inl.h
+++ b/napi-inl.h
@@ -5772,16 +5772,50 @@ inline void AsyncWorker::SuppressDestruct() {
   _suppress_destruct = true;
 }
 
+namespace details {
+inline void CallAsyncWorkerCallback(napi_env env,
+                                    napi_value recv,
+                                    napi_value func,
+                                    size_t argc,
+                                    const napi_value* argv) {
+  napi_value result;
+  napi_status status = napi_call_function(env, recv, func, argc, argv, &result);
+#if (NAPI_VERSION >= 10)
+  if (status == napi_cannot_run_js) {
+    return;
+  }
+#else
+  // Before Node-API 10, a terminating environment reports
+  // napi_pending_exception even though no exception is pending.
+  if (status == napi_pending_exception) {
+    bool is_exception_pending = false;
+    if (napi_is_exception_pending(env, &is_exception_pending) == napi_ok &&
+        !is_exception_pending) {
+      return;
+    }
+  }
+#endif
+  NAPI_THROW_IF_FAILED_VOID(env, status);
+}
+}  // namespace details
+
 inline void AsyncWorker::OnOK() {
   if (!_callback.IsEmpty()) {
-    _callback.Call(_receiver.Value(), GetResult(_callback.Env()));
+    napi_env env = _callback.Env();
+    HandleScope scope(env);
+    std::vector<napi_value> args = GetResult(env);
+    details::CallAsyncWorkerCallback(
+        env, _receiver.Value(), _callback.Value(), args.size(), args.data());
   }
 }
 
 inline void AsyncWorker::OnError(const Error& e) {
-  if (!_callback.IsEmpty()) {
-    _callback.Call(_receiver.Value(),
-                   std::initializer_list<napi_value>{e.Value()});
+  if (!_callback.IsEmpty() && !e.IsEmpty()) {
+    napi_env env = _callback.Env();
+    HandleScope scope(env);
+    napi_value arg = e.Value();
+    details::CallAsyncWorkerCallback(
+        env, _receiver.Value(), _callback.Value(), 1, &arg);
   }
 }
 
@@ -5829,7 +5863,16 @@ inline void AsyncWorker::OnWorkComplete(Napi::Env env, napi_status status) {
       if (_error.size() == 0) {
         OnOK();
       } else {
-        OnError(Error::New(_env, _error));
+        Error err;
+        napi_value str;
+        if (napi_create_string_utf8(_env, _error.data(), _error.size(), &str) ==
+            napi_ok) {
+          napi_value error;
+          if (napi_create_error(_env, nullptr, str, &error) == napi_ok) {
+            err = Error(_env, error);
+          }
+        }
+        OnError(err);
       }
       return nullptr;
     });

This minimal diff correctly passes all the test cases in your async_progress_worker_terminating_environment.js, including my newly added supress-destruct testcase, without using any env cleanup hook, or tracking tsfn finalization state.

@legendecas legendecas moved this from Need Triage to In Progress in Node-API Team Project Dec 4, 2026
@dave-365

dave-365 commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author

@KevinEady I covered the all issue ( node < 10, SuppressDestruct(), git diff) can you please check and proceed further.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants