Repository navigation
node 20.1.0 --loader seems trigger beforeExit when use await import #47929
Description
Activity
- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.loadersIssues and PRs related to ES module loaders.Issues and PRs related to ES module loaders.
on May 9, 2023 also reported here - with a minimal repro
// file.js process.on('beforeExit', () => { console.log('beforeExit') }) import('./anyfile.js') console.log('THIS CONSOLE LOG IS PREINTED')
./node file.js ✔ THIS CONSOLE LOG IS PREINTED beforeExit
./node --experimental-loader="data:text/javascript,export default true" file.js ✔ (node:62415) ExperimentalWarning: Custom ESM Loaders is an experimental feature and might change at any time (Use `node --trace-warnings ...` to show where the warning was created) THIS CONSOLE LOG IS PREINTED beforeExit beforeExit beforeExit
This is probably because the ESM loader uses
process.on('beforeExit')in a way that asynchronous work is scheduled in the callback. We should probably refactor that part anyway, I don't like that the internals use a public API that can be tampered with (for example withprocess.removeAllListeners('beforeExit');)Refs: https://nodejs.org/dist/latest-v20.x/docs/api/process.html#event-beforeexit
/cc @aduh95
Reacted by Moshe AtlowThe underlying issue being that
Atomics.waitAsyncdoes not keep the event loop alive, which has been reported to them already. That being said, we should be able to work around this without triggeringbeforeExitevents on the main thread (on the loader thread though, I don’t think we can work around it, and callingprocess.removeAllListeners('beforeExit')from the loader thread needs to be forbidden probably.- added a commit that references this issue
on May 14, 2023 - added 2 commits that reference this issue
on May 14, 2023 - added a commit that references this issue
on Nov 11, 2023 - added a commit that references this issue
on Nov 23, 2023 - added 2 commits that reference this issue
on Apr 25, 2024
Version
20.1.0
Platform
macos
What do you see instead?
My module will close the redis connection at the time of beforeExit, and the await import module (19.9.0) will not trigger beforeExit before.
In addition, the exit event is not triggered when use await import module