Description
Upgrading from Node 16.1 to 16.2 causes Node to crash, and I don't know how to debug the problem further. This is related to promises and maybe async_hooks or cls-hooked library, but I'm not knowledgeable enough to understand how or why it actually happens.
- Version: v16.2.0
- Platform: Darwin 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47 PDT 2021; root:xnu-7195.101.2~1/RELEASE_X86_64 x86_64
- Subsystem:
What steps will reproduce the bug?
I have cooked up a minimal repo here: https://github.com/heap-dk/node-16.2-crash/
The problem manifests itself somehow in relation to promises and async hooks... I think! The repo's readme shows the problem, the code is as minimal as I could make it to showcase the problem, and the commands to replicate the issue are simple. I hope that's good enough to be of interest to you.
The repo has dependencies on dd-trace and cls-hooked, but I don't think the problem is unique to those dependencies, rather I think it's related to their underlying use of async_hooks and somehow it results in a crash... 👀 But I'm guessing on those details so I very much hope someone with more knowledge about these systems can see the deeper pattern!
How often does it reproduce? Is there a required condition?
100% crash.
What is the expected behavior?
I didn't expect a Node patch bump to introduce a breaking behavior like this.
What do you see instead?
node[90090]: ../src/api/callback.cc:125:void node::InternalCallbackScope::Close(): Assertion `(env_->execution_async_id()) == (0)' failed.
1: 0x10dde07e5 node::Abort() (.cold.1) [/Users/jon/.nvm/versions/node/v16.2.0/bin/node]
2: 0x10ca93b39 node::Abort() [/Users/jon/.nvm/versions/node/v16.2.0/bin/node]
3: 0x10ca939a1 node::Assert(node::AssertionInfo const&) [/Users/jon/.nvm/versions/node/v16.2.0/bin/node]
4: 0x10c9c3cdd node::InternalCallbackScope::Close() [/Users/jon/.nvm/versions/node/v16.2.0/bin/node]
5: 0x10c9c35de node::InternalCallbackScope::~InternalCallbackScope() [/Users/jon/.nvm/versions/node/v16.2.0/bin/node]
6: 0x10ca5f4a3 node::StartExecution(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>) [/Users/jon/.nvm/versions/node/v16.2.0/bin/node]
7: 0x10c9c81fd node::LoadEnvironment(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>) [/Users/jon/.nvm/versions/node/v16.2.0/bin/node]
8: 0x10cad53f0 node::NodeMainInstance::Run(node::EnvSerializeInfo const*) [/Users/jon/.nvm/versions/node/v16.2.0/bin/node]
9: 0x10ca6197d node::Start(int, char**) [/Users/jon/.nvm/versions/node/v16.2.0/bin/node]
10: 0x7fff20653f3d start [/usr/lib/system/libdyld.dylib]
11: 0x2
error Command failed with signal "SIGABRT".
Additional information
To be honest I don't understand the finer points of this crash, but I'm creating this issue because my perception is that upgrading from Node 16.1 to 16.2 introduces this regression. I'm happy to add more context or try different solutions if that will be helpful.
And I want to take a moment to thank the maintainers of Node for making these releases available, crashing or not I'm grateful for your hard work.