forked from othiym23/node-continuation-local-storage
-
Notifications
You must be signed in to change notification settings - Fork 90
Open
Description
I think runPromise should exit context before return promise !
Otherwise, the context can be modify by operations outside this context.
Namespace.prototype.runPromise = function runPromise(fn) {
let context = this.createContext();
this.enter(context);
let promise = fn(context);
if (!promise || !promise.then || !promise.catch) {
throw new Error('fn must return a promise.');
}
if (DEBUG_CLS_HOOKED) {
debug2('CONTEXT-runPromise BEFORE: (' + this.name + ') currentUid:' + currentUid + ' len:' + this._set.length + ' ' + util.inspect(context));
}
this.exit(context)
return promise
.then(result => {
if (DEBUG_CLS_HOOKED) {
debug2('CONTEXT-runPromise AFTER then: (' + this.name + ') currentUid:' + currentUid + ' len:' + this._set.length + ' ' + util.inspect(context));
}
return result;
})
.catch(err => {
err[ERROR_SYMBOL] = context;
if (DEBUG_CLS_HOOKED) {
debug2('CONTEXT-runPromise AFTER catch: (' + this.name + ') currentUid:' + currentUid + ' len:' + this._set.length + ' ' + util.inspect(context));
}
throw err;
});
};Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels