Skip to content
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

Node.js crashes with native stack trace if throwing inside of an async function #53

Open
watson opened this issue Jul 23, 2024 · 0 comments

Comments

@watson
Copy link

watson commented Jul 23, 2024

This code crashes the Node.js process with a native stack trace ([email protected]):

const { test } = require('libtap')

test(() => {
  (async () => {
    throw new Error('foo')
  })()
})

This code doesn't crash with a native stack trace (notice the difference of the removed async symbol):

const { test } = require('libtap')

test(() => {
  (() => {
    throw new Error('foo')
  })()
})
Expand to see stack trace
TAP version 13
# Subtest
    not ok 1 - foo
      ---
      stack: |
        bar.js:5:11
        Test.<anonymous> (bar.js:6:5)
        Test.cb (node_modules/libtap/lib/test.js:127:40)
        node_modules/libtap/lib/test.js:369:21
        Test.main (node_modules/libtap/lib/test.js:376:7)
        Test.runMain (node_modules/libtap/lib/base.js:178:15)
        node_modules/libtap/lib/test.js:490:13
        TAP.writeSubComment (node_modules/libtap/lib/test.js:561:5)
      at:
        line: 5
        column: 11
        file: bar.js
      tapCaught: unhandledRejection
      source: |2
          (async () => {
            throw new Error('foo')
        ----------^
          })()
        })
      ...
    
    1..1
    # failed 1 test
not ok 1 # time=7.715ms


  #  node[53005]: void node::InternalCallbackScope::Close() at ../src/api/callback.cc:145
  #  Assertion failed: (env_->execution_async_id()) == (0)

----- Native stack trace -----

 1: 0x104de8404 node::Assert(node::AssertionInfo const&) [/Users/thomas.watson/.nvm/versions/node/v22.4.1/bin/node]
 2: 0x1069c5d14 node::InternalCallbackScope::Close() (.cold.2) [/Users/thomas.watson/.nvm/versions/node/v22.4.1/bin/node]
 3: 0x104d0cda4 node::InternalCallbackScope::Close() [/Users/thomas.watson/.nvm/versions/node/v22.4.1/bin/node]
 4: 0x104d0c7bc node::InternalCallbackScope::~InternalCallbackScope() [/Users/thomas.watson/.nvm/versions/node/v22.4.1/bin/node]
 5: 0x104e50470 node::PerIsolatePlatformData::RunForegroundTask(std::__1::unique_ptr<v8::Task, std::__1::default_delete<v8::Task>>) [/Users/thomas.watson/.nvm/versions/node/v22.4.1/bin/node]
 6: 0x104e4f1c0 node::PerIsolatePlatformData::FlushForegroundTasksInternal() [/Users/thomas.watson/.nvm/versions/node/v22.4.1/bin/node]
 7: 0x104e50728 node::NodePlatform::DrainTasks(v8::Isolate*) [/Users/thomas.watson/.nvm/versions/node/v22.4.1/bin/node]
 8: 0x104d0d730 node::SpinEventLoopInternal(node::Environment*) [/Users/thomas.watson/.nvm/versions/node/v22.4.1/bin/node]
 9: 0x104e29cc8 node::NodeMainInstance::Run(node::ExitCode*, node::Environment*) [/Users/thomas.watson/.nvm/versions/node/v22.4.1/bin/node]
10: 0x104e299dc node::NodeMainInstance::Run() [/Users/thomas.watson/.nvm/versions/node/v22.4.1/bin/node]
11: 0x104db0590 node::Start(int, char**) [/Users/thomas.watson/.nvm/versions/node/v22.4.1/bin/node]
12: 0x1879460e0 start [/usr/lib/dyld]
[1]    53005 abort      node bar.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant