Skip to content

Tracking issue for failure on crash of CallbackScope::Close on testing #979

@legendecas

Description

@legendecas

Refs: https://github.com/nodejs/node-addon-api/pull/976/files#diff-db9746a1646fe3119716304e4bc4d3fb6a1e8aac5f4ca11da036bb92102dae74R27

Mininal diffs that make test/callback_scope.js crashing:

diff --git a/test/callbackscope.js b/test/callbackscope.js
index 7396482..e561f2c 100644
--- a/test/callbackscope.js
+++ b/test/callbackscope.js
@@ -17,7 +17,30 @@ function checkAsyncHooks() {

 module.exports = require('./common').runTest(test);

-function test(binding) {
+async function test(binding) {
+  const asyncHooks = require('async_hooks');
+
+  async function foo() {
+    return new Promise(resolve => {
+      const hooks = asyncHooks.createHook({
+        destroy() {
+          hooks.disable();
+          resolve();
+        },
+      });
+      hooks.enable();
+    });
+  }
+  {
+    const future = foo();
+    const resource = new asyncHooks.AsyncResource('foo');
+    resource.emitDestroy();
+    await future;
+  }
+  testActual(binding);
+}
+
+function testActual(binding) {
   if (!checkAsyncHooks())
     return;

Crash backtrace:

node[72630]: ../src/api/callback.cc:122:void node::InternalCallbackScope::Close(): Assertion `(env_->execution_async_id()) == (0)' failed.
 1: 0x100096949 node::Abort() [/usr/local/opt/node@14/bin/node]
 2: 0x1000967d2 node::AppendExceptionLine(node::Environment*, v8::Local<v8::Value>, v8::Local<v8::Message>, node::ErrorHandlingMode) [/usr/local/opt/node@14/bin/node]
 3: 0x100005958 node::InternalCallbackScope::Close() [/usr/local/opt/node@14/bin/node]
 4: 0x100005de8 node::InternalMakeCallback(node::Environment*, v8::Local<v8::Object>, v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*, node::async_context) [/usr/local/opt/node@14/bin/node]
 5: 0x100006069 node::MakeCallback(v8::Isolate*, v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*, node::async_context) [/usr/local/opt/node@14/bin/node]
 6: 0x1000f1da3 node::ProcessEmit(node::Environment*, char const*, v8::Local<v8::Value>) [/usr/local/opt/node@14/bin/node]
 7: 0x100009ece node::EmitBeforeExit(node::Environment*) [/usr/local/opt/node@14/bin/node]
 8: 0x1000ce057 node::NodeMainInstance::Run() [/usr/local/opt/node@14/bin/node]
 9: 0x10007048a node::Start(int, char**) [/usr/local/opt/node@14/bin/node]
10: 0x7fff20630621 start [/usr/lib/system/libdyld.dylib]
fish: Job 1, 'node test/callbackscope.js' terminated by signal SIGABRT (Abort)

Tested Node.js versions:

  • v16.0.0: Crashing
  • v14.16.1: Crashing
  • v12.22.1: Not Crashing, test failed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions