Sitelet https://github.com/nodejs/node/issues/43182
Skip to content

Assertion failure when calling process.exit() from a Worker that has TLA #43182

Description

@aduh95

Version

master

Platform

macOS

Subsystem

worker_threads

What steps will reproduce the bug?

new worker_threads.Worker(new URL("data:text/javascript,process.exit(0);await new Promise(()=>{})"))

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

No response

What is the expected behavior?

No crash

What do you see instead?

$ out/Release/node -e 'new worker_threads.Worker(new url("data:text/javascript,process.exit(0);await new Promise(()=>{})"))'


#
# Fatal error in , line 0
# Check failed: (location_) != nullptr.
#
#
#
#FailureMessage Object: 0x700008060840
 1: 0x108604622 node::NodePlatform::GetStackTracePrinter()::$_3::__invoke() […/out/Release/node]
 2: 0x109772823 V8_Fatal(char const*, ...) […/out/Release/node]
 3: 0x108be671c v8::internal::SourceTextModule::ExecuteAsyncModule(v8::internal::Isolate*, v8::internal::Handle<v8::internal::SourceTextModule>) […/out/Release/node]
 4: 0x108be5f35 v8::internal::SourceTextModule::InnerModuleEvaluation(v8::internal::Isolate*, v8::internal::Handle<v8::internal::SourceTextModule>, v8::internal::ZoneForwardList<v8::internal::Handle<v8::internal::SourceTextModule> >*, unsigned int*) […/out/Release/node]
 5: 0x108be5d6b v8::internal::SourceTextModule::InnerModuleEvaluation(v8::internal::Isolate*, v8::internal::Handle<v8::internal::SourceTextModule>, v8::internal::ZoneForwardList<v8::internal::Handle<v8::internal::SourceTextModule> >*, unsigned int*) […/out/Release/node]
 6: 0x108be583b v8::internal::SourceTextModule::Evaluate(v8::internal::Isolate*, v8::internal::Handle<v8::internal::SourceTextModule>) […/out/Release/node]
 7: 0x10871b43c v8::Module::Evaluate(v8::Local<v8::Context>) […/out/Release/node]
 8: 0x10855c6ae node::loader::ModuleWrap::Evaluate(v8::FunctionCallbackInfo<v8::Value> const&) […/out/Release/node]
 9: 0x10877c9f8 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) […/out/Release/node]
10: 0x10877c54b v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) […/out/Release/node]
11: 0x10877bc2b v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) […/out/Release/node]
12: 0x1090d2b39 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit […/out/Release/node]
13: 0x109056a90 Builtins_InterpreterEntryTrampoline […/out/Release/node]
[1]    43848 trace trap  out/Release/node -e 

Additional information

The bug is reproducable on v14.x, v16.x, and v18.x lines.

Activity

  1. aduh95 commented on May 22, 2022

    @aduh95
    ContributorAuthor

    /cc @nodejs/workers

  2. added
    confirmed-bugIssues and PRs for confirmed bugs.
    workerIssues and PRs related to the worker_threads module and Worker API.
    on May 22, 2022
  3. legendecas commented on May 31, 2022

    @legendecas
    Member

    V8 asserts the evaluation of the module's async function to succeed without exception. However, the problem is that TerminateExecution initiated by process.exit is breaking that assumption. I'll work on this and submit a fix to v8.

  4. sajal50 commented on Jun 16, 2022

    @sajal50

    @legendecas, are you working on this?

  5. legendecas commented on Jun 17, 2022

    @legendecas
    Member
  6. legendecas commented on Jun 29, 2022

    @legendecas
    Member

    https://chromium-review.googlesource.com/c/v8/v8/+/3696493 has landed. I'll continue to investigate if node handles these termination exceptions properly.

  7. aduh95 commented on Jul 9, 2022

    @aduh95
    ContributorAuthor

    @legendecas I've tried to cherry-pick your commit in node repo, but it looks like it relies on V8 APIs that are not available in the version of V8 we are using. Do you know if it's worth a backport or if we'd be better off waiting for V8 10.5 to stabilize?

  8. legendecas commented on Jul 10, 2022

    @legendecas
    Member

    @aduh95 thanks for the ping. I think the patch should be straightforward to be backported. Submitted #43751 and added a test case for the issue.

  9. added a commit that references this issue on Jul 26, 2022
  10. added a commit that references this issue on Aug 2, 2022
  11. szmarczak commented on Sep 21, 2022

    @szmarczak
    Member

    Another reproduction case (it's weird, remove join and it works?):

    import { join } from 'node:path';
    import { isMainThread, Worker } from 'node:worker_threads';
    
    if (isMainThread) {
        new Worker(new URL(import.meta.url));
        await 0;
    } else {
        process.exit();
        join();
    }

    Is there a chance for this to be backported into Node.js 14?

  12. added a commit that references this issue on Oct 10, 2022
  13. legendecas commented on Oct 26, 2022

    @legendecas
    Member

    @szmarczak I tried a backport but V8 has changed a lot since v14. It might need a totally new patch for the issue on v14 (and a refresh review on the patch too).

  14. szmarczak commented on Oct 26, 2022

    @szmarczak
    Member

    No problem. Thanks for trying ❤️

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

    confirmed-bugIssues and PRs for confirmed bugs.workerIssues and PRs related to the worker_threads module and Worker API.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions