mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
async_hooks: fix ctx loss after nested ALS calls
PR-URL: https://github.com/nodejs/node/pull/32085 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
This commit is contained in:
parent
434d39dd67
commit
86ab4ee6e4
3 changed files with 50 additions and 23 deletions
|
@ -255,23 +255,21 @@ class AsyncLocalStorage {
|
|||
resource[this.kResourceStore] = store;
|
||||
}
|
||||
|
||||
_exit() {
|
||||
const resource = executionAsyncResource();
|
||||
if (resource) {
|
||||
resource[this.kResourceStore] = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
runSyncAndReturn(store, callback, ...args) {
|
||||
const resource = executionAsyncResource();
|
||||
const outerStore = resource[this.kResourceStore];
|
||||
this._enter(store);
|
||||
try {
|
||||
return callback(...args);
|
||||
} finally {
|
||||
this._exit();
|
||||
resource[this.kResourceStore] = outerStore;
|
||||
}
|
||||
}
|
||||
|
||||
exitSyncAndReturn(callback, ...args) {
|
||||
if (!this.enabled) {
|
||||
return callback(...args);
|
||||
}
|
||||
this.enabled = false;
|
||||
try {
|
||||
return callback(...args);
|
||||
|
@ -288,12 +286,17 @@ class AsyncLocalStorage {
|
|||
}
|
||||
|
||||
run(store, callback, ...args) {
|
||||
const resource = executionAsyncResource();
|
||||
const outerStore = resource[this.kResourceStore];
|
||||
this._enter(store);
|
||||
process.nextTick(callback, ...args);
|
||||
this._exit();
|
||||
resource[this.kResourceStore] = outerStore;
|
||||
}
|
||||
|
||||
exit(callback, ...args) {
|
||||
if (!this.enabled) {
|
||||
return process.nextTick(callback, ...args);
|
||||
}
|
||||
this.enabled = false;
|
||||
process.nextTick(callback, ...args);
|
||||
this.enabled = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue