Repository navigation
await Promise.resolve("import('./mod.mjs')").then(eval) rejects/segfaults in REPL #43681
Description
Activity
- changed the title
[-]`await Promise.resolve("import('./mod.js')").then(eval)` fails in REPL[/-][+]`await Promise.resolve("import('./mod.js')").then(eval)` rejects/segfaults in REPL[/+]on Jul 4, 2022 - changed the title
[-]`await Promise.resolve("import('./mod.js')").then(eval)` rejects/segfaults in REPL[/-][+]`await Promise.resolve("import('./mod.mjs')").then(eval)` rejects/segfaults in REPL[/+]on Jul 4, 2022 - addedreplIssues and PRs related to the REPL subsystem.Issues and PRs related to the REPL subsystem.
on Jul 5, 2022 - addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on Jul 5, 2022 I can repro this on main, this is a neat find, thanks.
@nodejs/loaders @nodejs/repl
When running the scripts sequentially, the
Local<Script>created at https://github.com/nodejs/node/blob/main/src/node_contextify.cc#L947 can outlive theContextifyScriptso https://github.com/nodejs/node/blob/main/src/module_wrap.cc#L594 may crash because theContextifyScriptis released and the access can be invalid.When running
console.log(6, await Promise.resolve('import("./mod.mjs")').then(eval));in a fresh REPL, the referrer script unexpectedly becomes theinternal/process/task_queues.jsinstead of the REPL script. This can be problematic as the host_defined_options is not the expected one for the REPL script.I'll try to dig into this.
Reacted by Benjamin Gruenbaum@legendecas I'm not sure whether it's related to this crash, but note that we are still using
CompileFunctionInContextwhich is deprecated in V8.Reacted by Chengzhong WuWhen running console.log(6, await Promise.resolve('import("./mod.mjs")').then(eval)); in a fresh REPL, the referrer script unexpectedly becomes the internal/process/task_queues.js instead of the REPL script. This can be problematic as the host_defined_options is not the expected one for the REPL script.
So, the reason I found this bug is that I was reading https://tc39.es/ecma262/#sec-hostmakejobcallback, which forces non-browser hosts to have a different behavior from browsers. HTML uses that host hook to implement support for
Promise.resolve('import(`./example.mjs`)').then(eval)(https://html.spec.whatwg.org/#hostmakejobcallback), so I wanted to test how Node.js behaves.So it's possible that the promise rejection (not the crash) is actually expected.
- This is actually expected in Node.js I argued at TC39 browsers should fail too in 2019 or so. However, they didn't like that. Notes term should be something about "incumbent realm". Node can allow it and ignore spec non-web expectations. We had to do same with JSON impoer assertions due to how web structured that semantics…On Tue, Jul 5, 2022, 3:59 PM Nicolò Ribaudo ***@***.***> wrote: When running console.log(6, await Promise.resolve('import("./mod.mjs")').then(eval)); in a fresh REPL, the referrer script unexpectedly becomes the internal/process/task_queues.js instead of the REPL script. This can be problematic as the host_defined_options is not the expected one for the REPL script. So, the reason I found this bug is that I was reading https://tc39.es/ecma262/#sec-hostmakejobcallback, which forces non-browser hosts to have a different behavior from browsers. HTML uses that host hook to implement support for Promise.resolve('import( ./example.mjs)').then(eval), so I wanted to test how Node.js behaves. So it's possible that the promise rejection (not the crash) is actually expected. — Reply to this email directly, view it on GitHub <#43681 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AABZJIZ3ZJXURUZJ7YW6Z2DVSSO2TANCNFSM52T5DMMQ> . You are receiving this because you are on a team that was mentioned.Message ID: ***@***.***>Reacted by Nicolò Ribaudo and Chengzhong Wu
Version
v18.4.0
Platform
Linux nic-XPS-15-9570 5.15.0-40-generic #43-Ubuntu SMP Wed Jun 15 12:54:21 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
modules
What steps will reproduce the bug?
Have an empty
mod.mjsfile, and amain.mjsfile with the following contents:If you run
node main.mjs, it works.However, if you open the REPL and copy-paste-run the first five lines one by one. Now kill the REPL, restart it, and run the sixth line: it throws
If you don't restart the REPL before running the sixth line, it almost always crashes with a segfault:
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
I assume that the last line should work in the REPL, because it works in a file and because all the other lines work in the REPL.
Even if the error is expected for some reason, it shouldn't segfault.
What do you see instead?
/
Additional information
No response