GeezerVison is showing github.com — test: fix unreliable assumption in js-native-api/test_cannot_run_js by joyeecheung · Pull Request #51898 · nodejs/node
Conversation
joyeecheung
commented
Feb 27, 2024
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Previously the test assumes that when the queued finalizer is run, it must be run at a point where env->can_call_into_js() is false (typically, during Environment shutdown), which is not certain. If GC kicks in early and the second pass finalizer is queued before the event loop runs the check callbacks, the finalizer would then be called in check callbacks (via native immediates), where the finalizer can still call into JS. Essentially, addons can't make assumptions about where the queued finalizer would be called. This patch updates the assertions in the test to account for that.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM as a hotfix, but the test will basically become useless once V8 12.2 lands, as it will always return napi_ok then.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Previously the test assumes that when the queued finalizer is run,
it must be run at a point where env->can_call_into_js() is false
(typically, during Environment shutdown), which is not certain.
If GC kicks in early and the second pass finalizer is queued before
the event loop runs the check callbacks, the finalizer would then
be called in check callbacks (via native immediates), where
the finalizer can still call into JS. Essentially, addons can't
make assumptions about where the queued finalizer would be called.
This patch updates the assertions in the test to account for that.
joyeecheung
commented
Feb 27, 2024
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
but the test will basically become useless once V8 12.2 lands, as it will always return napi_ok then.
That's not certain, it really depends on what the heap looks like when the addon is loaded. Any subtle change to the internals can delay the GC to happen after the check callbacks are called in the event loop (or not happen at all), and then it'll be napi_cannot_run_js again (and become a flaky nightmare). The fix just makes sure that it works for all cases (no matter GC kicks in before or after check callbacks, or if it doesn't happen at all)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
If this fixes the test, perhaps remove the flaky designation in
|
js-native-api/test_cannot_run_js/test: PASS,FLAKY |
?
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
If this fixes the test, perhaps remove the flaky designation in
Updated the status file - was the designation even working in the first place? It still got caught in the CI it seems, and locally the test runner still reports it. (I think it should've been marked as PASS,CRASH instead?)
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
If this fixes the test, perhaps remove the flaky designation in
Updated the status file - was the designation even working in the first place? It still got caught in the CI it seems, and locally the test runner still reports it. (I think it should've been marked as PASS,CRASH instead?)
Yes, it was working -- e.g. https://ci.nodejs.org/job/node-test-commit-ibmi/nodes=ibmi73-ppc64/1466/ (from #48180 (comment)) is yellow due to this test crashing and not red.
|
joyeecheung reacted with thumbs up emoji
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
It looks like the addon is failing to compile on Windows:
e.g. https://ci.nodejs.org/job/node-test-binary-windows-native-suites/21625/nodes=win10-vs2019-COMPILED_BY-vs2022/console
17:10:21 Failed to build addon in c:\workspace\node-test-binary-windows-native-suites\node\test\js-native-api\test_cannot_run_js:
17:10:21 Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
17:10:21 test_cannot_run_js.c
17:10:21 c:\workspace\node-test-binary-windows-native-suites\node\test\js-native-api\test_cannot_run_js\test_cannot_run_js.c(28,1): error C2121: '#': invalid character: possibly the result of a macro expansion [c:\workspace\node-test-binary-windows-native-suites\node\test\js-native-api\test_cannot_run_js\build\test_cannot_run_js.vcxproj]
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
It looks like the addon is failing to compile on Windows
I tried this locally and can confirm the behavior. What fixed the compilation for me was this. @joyeecheung if you think it's good, feel free to apply it.
diff --git a/test/js-native-api/test_cannot_run_js/test_cannot_run_js.c b/test/js-native-api/test_cannot_run_js/test_cannot_run_js.c
index 925a7117d06..19cc7ae9058 100644
--- a/test/js-native-api/test_cannot_run_js/test_cannot_run_js.c
+++ b/test/js-native-api/test_cannot_run_js/test_cannot_run_js.c
@@ -21,12 +21,13 @@ static void Finalize(napi_env env, void* data, void* hint) {
// or during environment shutdown (where napi_cannot_run_js or
// napi_pending_exception is returned). This is not deterministic from
// the point of view of the addon.
- NODE_API_NOGC_ASSERT_RETURN_VOID(
#ifdef NAPI_EXPERIMENTAL
+ NODE_API_NOGC_ASSERT_RETURN_VOID(
result == napi_cannot_run_js || result == napi_ok,
"getting named property from global in finalizer should succeed "
"or return napi_cannot_run_js");
#else
+ NODE_API_NOGC_ASSERT_RETURN_VOID(
result == napi_pending_exception || result == napi_ok,
"getting named property from global in finalizer should succeed "
"or return napi_pending_exception");
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
marco-ippolito
pushed a commit
that referenced
this pull request
Mar 1, 2024
Previously the test assumes that when the queued finalizer is run,
it must be run at a point where env->can_call_into_js() is false
(typically, during Environment shutdown), which is not certain.
If GC kicks in early and the second pass finalizer is queued before
the event loop runs the check callbacks, the finalizer would then
be called in check callbacks (via native immediates), where
the finalizer can still call into JS. Essentially, addons can't
make assumptions about where the queued finalizer would be called.
This patch updates the assertions in the test to account for that.
PR-URL: #51898
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
richardlau
pushed a commit
that referenced
this pull request
Mar 25, 2024
Previously the test assumes that when the queued finalizer is run,
it must be run at a point where env->can_call_into_js() is false
(typically, during Environment shutdown), which is not certain.
If GC kicks in early and the second pass finalizer is queued before
the event loop runs the check callbacks, the finalizer would then
be called in check callbacks (via native immediates), where
the finalizer can still call into JS. Essentially, addons can't
make assumptions about where the queued finalizer would be called.
This patch updates the assertions in the test to account for that.
PR-URL: #51898
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
richardlau
pushed a commit
that referenced
this pull request
Sep 26, 2024
Previously the test assumes that when the queued finalizer is run,
it must be run at a point where env->can_call_into_js() is false
(typically, during Environment shutdown), which is not certain.
If GC kicks in early and the second pass finalizer is queued before
the event loop runs the check callbacks, the finalizer would then
be called in check callbacks (via native immediates), where
the finalizer can still call into JS. Essentially, addons can't
make assumptions about where the queued finalizer would be called.
This patch updates the assertions in the test to account for that.
PR-URL: #51898
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewers
+1 more reviewer
targos
targos approved these changes
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Labels
commit-queue-squash
PRs the Commit Queue should land as one squashed commit.
needs-ci
PRs that need a full CI run.
node-api
Issues and PRs related to Node-API.
test
Issues and PRs related to Node.js core tests and test infrastructure.
Milestone
No milestone
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.
|