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 when using ESM dynamic import repeatedly in special circumstances #39964

Open
mkg20001 opened this issue Aug 31, 2021 · 3 comments
Open
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs.

Comments

@mkg20001
Copy link

mkg20001 commented Aug 31, 2021

Version

v16.8.0

Platform

Linux mkg-razer 5.10.61 #1-NixOS SMP Thu Aug 26 12:51:21 UTC 2021 x86_64 GNU/Linux

Subsystem

ESM modules

What steps will reproduce the bug?

  • Create a package.json with at least "type": "module" set
  • Create a file b.js with the following contents
export default () => {}
  • Open a nodeJS repl and paste the following
async function require (thing) {
  const imported = await import(thing) // "dynamic import"
  return Object.assign(imported.default, imported)
}

require('./b.js')

Wait a few seconds and run require('./b.js') again

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

Sometimes it doesn't segfault, try running require('./b.js') again a few times, or try something like require('./b.js').then(console.log)

What is the expected behavior?

It should return the module

What do you see instead?

It segfaults

Segmentation fault (Speicherabzug geschrieben)

Additional information

No response

@devsnek
Copy link
Member

devsnek commented Aug 31, 2021

Duplicate of #35889

@devsnek devsnek marked this as a duplicate of #35889 Aug 31, 2021
@devsnek devsnek closed this as completed Aug 31, 2021
@aduh95 aduh95 added the duplicate Issues and PRs that are duplicates of other issues or PRs. label Aug 31, 2021
@bnoordhuis
Copy link
Member

Reopening because of #35889 (comment). I can reproduce the segfault with v19.x but it may not be the exact same bug as #35889 because it only happens in the REPL and doesn't use importModuleDynamically.

FWIW, it does not reproduce with the test case below:

// echo '{"type":"module"}' > package.json
import fs from 'node:fs'
let i = 0
async function go() {
  const filename = `./m${i++}.js`
  fs.writeFileSync(filename, 'export default() => {}')
  const m = await import(filename)
  Object.assign(m.default, m)
  setTimeout(go, 250)
}
go()

@bnoordhuis bnoordhuis reopened this Apr 26, 2023
@mkg20001
Copy link
Author

mkg20001 commented May 5, 2023

The bug reproduces only after a few tries sometimes, so maybe 1) it would need to be ran as setInterval or 2) it would need to be ran after the module has loaded (as the bug may be related to the module being loaded again or something like it)

Edit: Tried interval with my original repro but that didn't work when ran via node test.js. It works reliably on REPL with both interval and timeout, so it requires the module to be already loaded to cause the issue.

async function require (thing) {
  const imported = await import(thing) // "dynamic import"
  return Object.assign(imported.default, imported)
}

require('./b.js')

setTimeout(() => require('./b.js'), 1000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Issues and PRs that are duplicates of other issues or PRs.
Projects
None yet
Development

No branches or pull requests

4 participants