Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schulhof <gabriel.schulhof@intel.com>2020-07-16 01:45:53 +0300
committerGabriel Schulhof <gabriel.schulhof@intel.com>2020-07-24 09:28:09 +0300
commita74a6e3ba131752225a527d915593d7e413b1594 (patch)
tree7e6b88a32d82b69335adc235261b5454f48ba9a2 /benchmark
parentd1e4e8eaba400d152f0209c6eaccaea9c9950c49 (diff)
n-api: run all finalizers via SetImmediate()
Throwing an exception from a finalizer can cause the following fatal error: Error: async hook stack has become corrupted (actual: 2, expected: 0) 1: 0x970b5a node::InternalCallbackScope::~InternalCallbackScope() [./node] 2: 0x99dda0 node::Environment::RunTimers(uv_timer_s*) [./node] 3: 0x13d8b22 [./node] 4: 0x13dbe42 uv_run [./node] 5: 0xa57974 node::NodeMainInstance::Run() [./node] 6: 0x9dbc17 node::Start(int, char**) [./node] 7: 0x7f4965417f43 __libc_start_main [/lib64/libc.so.6] 8: 0x96f4ae _start [./node] By https://github.com/nodejs/node/issues/34341#issuecomment-658426281, calling into JS from a finalizer and/or throwing exceptions from there is not advised, because the stack may or may not be set up for JS execution. The best solution is to run the user's finalizer from a `SetImmediate()` callback. Signed-off-by: Gabriel Schulhof <gabriel.schulhof@intel.com> Fixes: https://github.com/nodejs/node/issues/34341 PR-URL: https://github.com/nodejs/node/pull/34386 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/napi/ref/index.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/benchmark/napi/ref/index.js b/benchmark/napi/ref/index.js
index 3a5e1988275..a8642a54b21 100644
--- a/benchmark/napi/ref/index.js
+++ b/benchmark/napi/ref/index.js
@@ -10,8 +10,10 @@ function callNewWeak() {
function main({ n }) {
addon.count = 0;
bench.start();
- while (addon.count < n) {
- callNewWeak();
- }
- bench.end(n);
+ new Promise((resolve) => {
+ (function oneIteration() {
+ callNewWeak();
+ setImmediate(() => ((addon.count < n) ? oneIteration() : resolve()));
+ })();
+ }).then(() => bench.end(n));
}