Skip to content

Segfault importing ESM module twice #33233

Closed

Description

@jasnell

@nodejs/modules...

Welcome to Node.js v14.1.0.
Type ".help" for more information.
> import('piscina')
Promise { <pending> }
> import('piscina').then(console.log)
Promise { <pending> }
> [Module] {
  Piscina: [Function: Piscina],
  default: [Function: Piscina],
  isWorkerThread: false,
  version: '1.2.0',
  workerData: undefined
}
> import('piscina').then(console.log)
Segmentation fault (core dumped)

Spotted this while working on a module. Happens regularly for me with any ESM. Calling import twice on the same module leads to a segfault. Happens regularly but may take a few calls to import to trigger... lldb backtrace shows:

* thread #1, name = 'node', stop reason = signal SIGSEGV: invalid address (fault address: 0x10)
  * frame #0: 0x0000000000978050 node`node::loader::ImportModuleDynamically(v8::Local<v8::Context>, v8::Local<v8::ScriptOrModule>, v8::Local<v8::String>) (.cold.291)
    frame #1: 0x000000000431adc0
    frame #2: 0x0000000000ce6a58 node`v8::internal::Isolate::RunHostImportModuleDynamicallyCallback(v8::internal::Handle<v8::internal::Script>, v8::internal::Handle<v8::internal::Object>) + 120
    frame #3: 0x000000000105530f node`v8::internal::Runtime_DynamicImportCall(int, unsigned long*, v8::internal::Isolate*) + 175

Activity

  1. added
    esm
    on May 4, 2020
  2. added
    repl
    on May 4, 2020
  3. targos commented on May 4, 2020

    @targos
    Member

    I added the repl label because it seems to be only reproducible in that environment.

  4. targos commented on May 4, 2020

    @targos
    Member

    stack trace in debug build:

    #0  node::loader::ImportModuleDynamically (context=..., referrer=..., specifier=...) at ../../src/module_wrap.cc:527
    #1  0x000000000142a34a in v8::internal::Isolate::RunHostImportModuleDynamicallyCallback (this=this@entry=0x7282930, referrer=..., specifier=..., specifier@entry=...) at ../../deps/v8/include/v8.h:336
    #2  0x00000000019d4886 in v8::internal::__RT_impl_Runtime_DynamicImportCall (args=..., isolate=0x7282930) at ../../deps/v8/src/runtime/runtime-module.cc:27
    #3  0x00000000019d5bc2 in v8::internal::Runtime_DynamicImportCall (args_length=2, args_object=0x7ffffe6365a0, isolate=0x7282930) at ../../deps/v8/src/runtime/runtime-module.cc:15
    #4  0x0000000001f7839b in Builtins_CEntry_Return1_DontSaveFPRegs_ArgvInRegister_NoBuiltinExit () at ../../deps/v8/../../deps/v8/src/builtins/promise-misc.tq:91
    #5  0x00000000021d0fb6 in Builtins_CallRuntimeHandler () at ../../deps/v8/src/interpreter/interpreter-generator.cc:1724
    

    contextify::ContextifyScript* wrap = env->id_to_script_map.find(id)->second;

  5. devsnek commented on May 4, 2020

    @devsnek
    Member

    After some light debugging, this appears to be related to v8:9968.

  6. added
    v8 engine
    vm
    confirmed-bug
    on May 7, 2020
  7. bmeck commented on Jul 14, 2020

    @bmeck
    Member

    I've made a PR to mitigate this #34372

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-bugesmreplv8 enginevm

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions