Repository navigation
Fix error reporting during worker termination - #506
Open
Saúl Ponce (GalaxiasKyklos) wants to merge 1 commit into
Open
Saúl Ponce (GalaxiasKyklos) wants to merge 1 commit into
Saúl Ponce (GalaxiasKyklos) wants to merge 1 commit into
Conversation
Avoid constructing JavaScript error values after a Node-API environment starts terminating, and add a deterministic hosted-worker regression test.\n\nFixes microsoft#505.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot started reviewing on behalf of
Saúl Ponce (GalaxiasKyklos)
October 13, 2026 18:57
View session
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The newly introduced fallback path lacks deterministic test coverage.
1 open finding
What changed in this PR
Improves worker-termination error handling so pending or closing Node-API environments do not abort the process.
Changes:
- Adds termination-safe exception checks and direct-runtime fallback handling.
- Adds unit and hosted-CLR regression coverage.
- Excludes the hosted-specific regression from NativeAOT tests.
| File | Description |
|---|---|
src/NodeApi/JSError.cs |
Implements termination-safe error reporting. |
test/JSErrorTests.cs |
Tests preflight termination states. |
test/TestCases/napi-dotnet/Errors.cs |
Adds the managed regression helper. |
test/TestCases/napi-dotnet/worker_termination_during_call.js |
Exercises worker termination during a managed call. |
test/NativeAotTests.cs |
Excludes the hosted-CLR-specific scenario. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+293
to
+298
| catch (JSException) | ||
| { | ||
| // Termination may begin after the check above, causing any of the N-API operations used | ||
| // to construct or augment the JS Error object to fail. Fall back to the direct runtime | ||
| // error API, which does not require creating or inspecting any JS values. | ||
| napi_status fallbackStatus = runtime.ThrowError(env, code: null, message); |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #505.
Summary
ThrowErrorAPI when worker termination races JavaScript error constructionTesting
dotnet test test\NodeApi.Test.csproj -f net10.0 -c Debug --filter "FullyQualifiedName~JSErrorTests"dotnet test test\NodeApi.Test.csproj -f net10.0 -c Debug --filter "FullyQualifiedName~HostedClrTests&DisplayName~napi-dotnet/errors|FullyQualifiedName~HostedClrTests&DisplayName~worker_termination_during_call"