@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
I added the repl label because it seems to be only reproducible in that environment.
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
https://github.com/nodejs/node/blob/c81e5f699e80fa5c0a201ae4c34e455c99e52a20/src/module_wrap.cc#L527
After some light debugging, this appears to be related to v8:9968.
I've made a PR to mitigate this https://github.com/nodejs/node/pull/34372