mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
async_hooks: avoid GC tracking of AsyncResource in ALS
Manually destroy the AsyncResource created by AsyncLocalStore.run() to avoid unneeded GC tracking in case a destroy hooks is present. PR-URL: https://github.com/nodejs/node/pull/34653 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
33505e2dbd
commit
014feecc44
1 changed files with 6 additions and 2 deletions
|
@ -253,6 +253,7 @@ const storageHook = createHook({
|
|||
}
|
||||
});
|
||||
|
||||
const defaultAlsResourceOpts = { requireManualDestroy: true };
|
||||
class AsyncLocalStorage {
|
||||
constructor() {
|
||||
this.kResourceStore = Symbol('kResourceStore');
|
||||
|
@ -293,8 +294,11 @@ class AsyncLocalStorage {
|
|||
if (ObjectIs(store, this.getStore())) {
|
||||
return callback(...args);
|
||||
}
|
||||
const resource = new AsyncResource('AsyncLocalStorage');
|
||||
return resource.runInAsyncScope(() => {
|
||||
const resource = new AsyncResource('AsyncLocalStorage',
|
||||
defaultAlsResourceOpts);
|
||||
// Calling emitDestroy before runInAsyncScope avoids a try/finally
|
||||
// It is ok because emitDestroy only schedules calling the hook
|
||||
return resource.emitDestroy().runInAsyncScope(() => {
|
||||
this.enterWith(store);
|
||||
return callback(...args);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue