Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault importing ESM module twice #33233

Closed
jasnell opened this issue May 4, 2020 · 4 comments
Closed

Segfault importing ESM module twice #33233

jasnell opened this issue May 4, 2020 · 4 comments
Labels
confirmed-bug Issues with confirmed bugs. esm Issues and PRs related to the ECMAScript Modules implementation. repl Issues and PRs related to the REPL subsystem. v8 engine Issues and PRs related to the V8 dependency. vm Issues and PRs related to the vm subsystem.

Comments

@jasnell
Copy link
Member

jasnell commented May 4, 2020

@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
@jasnell jasnell added the esm Issues and PRs related to the ECMAScript Modules implementation. label May 4, 2020
@targos targos added the repl Issues and PRs related to the REPL subsystem. label May 4, 2020
@targos
Copy link
Member

targos commented May 4, 2020

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

@targos
Copy link
Member

targos commented May 4, 2020

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;

@devsnek
Copy link
Member

devsnek commented May 4, 2020

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

@BridgeAR BridgeAR added v8 engine Issues and PRs related to the V8 dependency. vm Issues and PRs related to the vm subsystem. confirmed-bug Issues with confirmed bugs. labels May 7, 2020
@bmeck
Copy link
Member

bmeck commented Jul 14, 2020

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
Labels
confirmed-bug Issues with confirmed bugs. esm Issues and PRs related to the ECMAScript Modules implementation. repl Issues and PRs related to the REPL subsystem. v8 engine Issues and PRs related to the V8 dependency. vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

No branches or pull requests

5 participants