-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
n-api: do not require JS Context for napi_async_destroy()
#27255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7947f48
src: add `Environment` overload of `EmitAsyncDestroy`
addaleax 4128307
n-api: do not require JS Context for `napi_async_destroy()`
addaleax 66f6944
src: do not require JS Context for `~AsyncResoure()`
addaleax f880b4f
fixup! n-api: do not require JS Context for `napi_async_destroy()`
addaleax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
44 changes: 44 additions & 0 deletions
44
test/node-api/test_make_callback/test-async-hooks-gcable.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
// Flags: --gc-interval=100 --gc-global | ||
|
||
const common = require('../../common'); | ||
const assert = require('assert'); | ||
const async_hooks = require('async_hooks'); | ||
const { createAsyncResource } = require(`./build/${common.buildType}/binding`); | ||
|
||
// Test for https://github.com/nodejs/node/issues/27218: | ||
// napi_async_destroy() can be called during a regular garbage collection run. | ||
|
||
const hook_result = { | ||
id: null, | ||
init_called: false, | ||
destroy_called: false, | ||
}; | ||
|
||
const test_hook = async_hooks.createHook({ | ||
init: (id, type) => { | ||
if (type === 'test_gcable') { | ||
hook_result.id = id; | ||
hook_result.init_called = true; | ||
} | ||
}, | ||
destroy: (id) => { | ||
if (id === hook_result.id) hook_result.destroy_called = true; | ||
}, | ||
}); | ||
|
||
test_hook.enable(); | ||
createAsyncResource(); | ||
|
||
// Trigger GC. This does *not* use global.gc(), because what we want to verify | ||
// is that `napi_async_destroy()` can be called when there is no JS context | ||
// on the stack at the time of GC. | ||
// Currently, using --gc-interval=100 + 1M elements seems to work fine for this. | ||
const arr = new Array(1024 * 1024); | ||
for (let i = 0; i < arr.length; i++) | ||
arr[i] = {}; | ||
|
||
assert.strictEqual(hook_result.destroy_called, false); | ||
setImmediate(() => { | ||
assert.strictEqual(hook_result.destroy_called, true); | ||
}); |
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.
Uh oh!
There was an error while loading. Please reload this page.