node icon indicating copy to clipboard operation
node copied to clipboard

Node SEA with `useSnapshot` cannot start worker thread

Open nomagick opened this issue 1 year ago • 3 comments

Version

v22.11.0

Platform

Darwin Mac.lan 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:03:11 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6020 arm64

Subsystem

sea

What steps will reproduce the bug?

Generate a SEA and start a worker thread in it

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

Thread can be started.

What do you see instead?

Native stack trace

Additional information


  #  ./out.bin[76089]: MaybeLocal<v8::Value> node::StartExecution(node::Environment *, node::StartExecutionCallback) at ../src/node.cc:378
  #  Assertion failed: !(sea.use_snapshot()) || (!env->snapshot_deserialize_main().IsEmpty())

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

 1: 0x1006b3778 node::Assert(node::AssertionInfo const&) [/Users/yanlong.wang/out.bin]
 2: 0x1022b7664 node::StartExecution(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>) (.cold.1) [/Users/yanlong.wang/out.bin]
 3: 0x10066dc04 node::StartExecution(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>) [/Users/yanlong.wang/out.bin]
 4: 0x1005d6460 node::LoadEnvironment(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>, std::__1::function<void (node::Environment*, v8::Local<v8::Value>, v8::Local<v8::Value>)>) [/Users/yanlong.wang/out.bin]
 5: 0x1007a48bc node::worker::Worker::Run() [/Users/yanlong.wang/out.bin]
 6: 0x1007a8b0c node::worker::Worker::StartThread(v8::FunctionCallbackInfo<v8::Value> const&)::$_3::__invoke(void*) [/Users/yanlong.wang/out.bin]
 7: 0x192a832e4 _pthread_start [/usr/lib/system/libsystem_pthread.dylib]
 8: 0x192a7e0fc thread_start [/usr/lib/system/libsystem_pthread.dylib]
[1]    76089 abort      ./out.bin

nomagick avatar Nov 29 '24 16:11 nomagick

This also breaks the esm loader hooks because it also runs in a thread.

nomagick avatar Nov 29 '24 16:11 nomagick

Looks like here:

https://github.com/nodejs/node/blob/03ec900e0729f48de61fa15954e125ad19915960/src/node.cc#L322-L350

nomagick avatar Nov 30 '24 09:11 nomagick

Hmm, looks like we just need to skip the SEA stuff for worker threads during bootstrap, since that's meant for the main thread anyway.

joyeecheung avatar Dec 03 '24 12:12 joyeecheung