Uh oh!
There was an error while loading. Please reload this page.
process: port on-exit-leak-free to core - #53239
Conversation
nodejs-github-bot
commented
May 31, 2024
Review requested:
|
mcollina
left a comment
There was a problem hiding this comment.
Given this is per-thread, you'd need to add some test that verifies this for multi-threading scenarios.
Can you add a reference that those were extracted by my module, with its license? Thx.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
nodejs-github-bot
commented
Jun 9, 2024
nodejs-github-bot
commented
Jun 9, 2024
nodejs-github-bot
commented
Jun 9, 2024
H4ad
commented
Jun 9, 2024
/cc @nodejs/tsc pinging to give some visibility on this change since it introduces something new to |
H4ad
commented
Jun 9, 2024
Added block until friday (06/14) to see if there's any objection, otherwise I will remove |
RafaelGSS
left a comment
There was a problem hiding this comment.
Left a couple of comments, but, it's still unclear to me why we need it on core instead of using the npm package directly. It's not very common usage by Node.js developers I assume.
FWIW I will review it properly before the TSC meeting.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
I think we should emit an experimental warning here.
There was a problem hiding this comment.
Added on register, registerBeforeExit and unregister.
mcollina
commented
Jun 10, 2024
The end goal of @H4ad is to add a logging utility to Node.js. This is needed to do it properly, i.e. flush all the buffered logs when |
H4ad
commented
Jul 11, 2024
Force pushed due to the error on mac-os test. @cjinhuo I posted a comment on your issue, but try reading the docs that this PR introduces about this feature, maybe it can help you understand what is going on. |
nodejs-github-bot
commented
Jul 11, 2024
nodejs-github-bot
commented
Jul 11, 2024
Landed in 05bb4a7 |
PR-URL: #53239 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Notable changes: http: * (SEMVER-MINOR) expose websockets (Natalia Venditto) #53721 module: * add __esModule to require()'d ESM (Joyee Cheung) #52166 path: * (SEMVER-MINOR) add `matchGlob` method (Aviv Keller) #52881 process: * (SEMVER-MINOR) port on-exit-leak-free to core (Vinicius Lourenço) #53239 stream: * (SEMVER-MINOR) pipeline wait for close before calling the callback (jakecastelli) #53462 worker: * (SEMVER-MINOR) add postMessageToThread (Paolo Insogna) #53682 PR-URL: #53826
PR-URL: #53239 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Notable changes: http: * (SEMVER-MINOR) expose websockets (Natalia Venditto) #53721 lib: * (SEMVER-MINOR) add `node:sqlite` module (Colin Ihrig) #53752 module: * add `__esModule` to `require()`'d ESM (Joyee Cheung) #52166 path: * (SEMVER-MINOR) add `matchesGlob` method (Aviv Keller) #52881 process: * (SEMVER-MINOR) port on-exit-leak-free to core (Vinicius Lourenço) #53239 stream: * (SEMVER-MINOR) pipeline wait for close before calling the callback (jakecastelli) #53462 test_runner: * support glob matching coverage files (Aviv Keller) #53553 worker: * (SEMVER-MINOR) add `postMessageToThread` (Paolo Insogna) #53682 PR-URL: #53826
Notable changes: http: * (SEMVER-MINOR) expose websockets (Natalia Venditto) #53721 lib: * (SEMVER-MINOR) add `node:sqlite` module (Colin Ihrig) #53752 module: * add `__esModule` to `require()`'d ESM (Joyee Cheung) #52166 path: * (SEMVER-MINOR) add `matchesGlob` method (Aviv Keller) #52881 process: * (SEMVER-MINOR) port on-exit-leak-free to core (Vinicius Lourenço) #53239 stream: * (SEMVER-MINOR) pipeline wait for close before calling the callback (jakecastelli) #53462 test_runner: * support glob matching coverage files (Aviv Keller) #53553 worker: * (SEMVER-MINOR) add `postMessageToThread` (Paolo Insogna) #53682 PR-URL: #53826
Notable changes: http: * (SEMVER-MINOR) expose websockets (Natalia Venditto) #53721 lib: * (SEMVER-MINOR) add `node:sqlite` module (Colin Ihrig) #53752 module: * add `__esModule` to `require()`'d ESM (Joyee Cheung) #52166 path: * (SEMVER-MINOR) add `matchesGlob` method (Aviv Keller) #52881 process: * (SEMVER-MINOR) port on-exit-leak-free to core (Vinicius Lourenço) #53239 stream: * (SEMVER-MINOR) pipeline wait for close before calling the callback (jakecastelli) #53462 test_runner: * support glob matching coverage files (Aviv Keller) #53553 worker: * (SEMVER-MINOR) add `postMessageToThread` (Paolo Insogna) #53682 PR-URL: #53826
Notable changes: http: * (SEMVER-MINOR) expose websockets (Natalia Venditto) #53721 lib: * (SEMVER-MINOR) add `node:sqlite` module (Colin Ihrig) #53752 module: * add `__esModule` to `require()`'d ESM (Joyee Cheung) #52166 path: * (SEMVER-MINOR) add `matchesGlob` method (Aviv Keller) #52881 process: * (SEMVER-MINOR) port on-exit-leak-free to core (Vinicius Lourenço) #53239 stream: * (SEMVER-MINOR) pipeline wait for close before calling the callback (jakecastelli) #53462 test_runner: * support glob matching coverage files (Aviv Keller) #53553 worker: * (SEMVER-MINOR) add `postMessageToThread` (Paolo Insogna) #53682 PR-URL: #53826
PR-URL: nodejs#53239 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Notable changes: http: * (SEMVER-MINOR) expose websockets (Natalia Venditto) nodejs#53721 lib: * (SEMVER-MINOR) add `node:sqlite` module (Colin Ihrig) nodejs#53752 module: * add `__esModule` to `require()`'d ESM (Joyee Cheung) nodejs#52166 path: * (SEMVER-MINOR) add `matchesGlob` method (Aviv Keller) nodejs#52881 process: * (SEMVER-MINOR) port on-exit-leak-free to core (Vinicius Lourenço) nodejs#53239 stream: * (SEMVER-MINOR) pipeline wait for close before calling the callback (jakecastelli) nodejs#53462 test_runner: * support glob matching coverage files (Aviv Keller) nodejs#53553 worker: * (SEMVER-MINOR) add `postMessageToThread` (Paolo Insogna) nodejs#53682 PR-URL: nodejs#53826
This PR basically ports on-exit-leak-free to core, in their words:
This module was created by @mcollina, so all the credits for him, I'm just doing the port.
Motivation
This library was proposed to be introduced on core previously on issue #48058 via the following syntax:
But the main arguments against introducing it were:
FinalizationRegistryis an anti-pattern, not recommended to close files automatically, and best to avoid when possible (said by the authors of the API) (ref comment)FinalizationRegistrysince it is a standard. (ref comment)To address the arguments above, I made some changes:
finalizationobject insideprocessobject that wraps the methods ofon-exit-leak-free.on-exit-leak-freehas more than 5M downloads per month, so it's a demanded feature.APIs Introduced
Now we have three new methods of
process.finalization:register: Accepts two arguments,objandfn, and executes thefnwhen theexitevent is emitted.fnis a function that will be called withobjregistered and theevent, which isexit.registerBeforeExit: Accepts two arguments,objandfn, and executes thefnwhen thebeforeExitevent is emitted.fnis a function that will be called withobjregistered and theevent, which isbeforeExit.unregister: Accepts one argumentobjto unregister the object.About moving away from classes (like aduh said about creating a new one), I think exposing functions was better than creating a class since we want to be able to use/call those methods in any place we want. But I'm open to better API design for these features.
TODO
I will wait for a few folks to manifest about introducing this feature (in the current state) before spending time creating documentation that could be totally changed or not used, so I will keep it as a draft for a couple of days.