镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Node SEA with useSnapshot cannot start worker thread #56077

Description

@nomagick

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

Activity

nomagick commented on Nov 29, 2024

@nomagick
Author

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

nomagick commented on Nov 30, 2024

@nomagick
Author

Looks like here:

node/src/node.cc

Lines 322 to 350 in 03ec900

#ifndef DISABLE_SINGLE_EXECUTABLE_APPLICATION
if (sea::IsSingleExecutable()) {
sea::SeaResource sea = sea::FindSingleExecutableResource();
// The SEA preparation blob building process should already enforce this,
// this check is just here to guard against the unlikely case where
// the SEA preparation blob has been manually modified by someone.
CHECK_IMPLIES(sea.use_snapshot(),
!env->snapshot_deserialize_main().IsEmpty());
}
#endif
// Ignore env file if we're in watch mode.
// Without it env is not updated when restarting child process.
// Child process has --watch flag removed, so it will load the file.
if (env->options()->has_env_file_string && !env->options()->watch_mode) {
per_process::dotenv_file.SetEnvironment(env);
}
// TODO(joyeecheung): move these conditions into JS land and let the
// deserialize main function take precedence. For workers, we need to
// move the pre-execution part into a different file that can be
// reused when dealing with user-defined main functions.
if (!env->snapshot_deserialize_main().IsEmpty()) {
return env->RunSnapshotDeserializeMain();
}
if (env->worker_context() != nullptr) {
return StartExecution(env, "internal/main/worker_thread");
}

joyeecheung commented on Dec 3, 2024

@joyeecheung
Member

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.

added
snapshotIssues and PRs related to the startup snapshot.
on Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    single-executableIssues and PRs related to single-executable applications.snapshotIssues and PRs related to the startup snapshot.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions