Skip to content

Commit

Permalink
fix(context): fixed runPromise mem leak and incorrect propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
eliabecardoso committed Jul 21, 2023
1 parent 0ff594b commit 3471d3a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions context-legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,24 @@ Namespace.prototype.runPromise = function runPromise(fn) {
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(' BEFORE runPromise: ' + this.name + ' uid:' + currentUid + ' len:' + this._set.length + ' ' +
util.inspect(context));
util.inspect(context));
}

this.exit(context);

return promise
.then(result => {
if (DEBUG_CLS_HOOKED) {
debug2(' AFTER runPromise: ' + this.name + ' uid:' + currentUid + ' len:' + this._set.length + ' ' +
util.inspect(context));
}
this.exit(context);
return result;
})
.catch(err => {
Expand All @@ -151,7 +153,6 @@ Namespace.prototype.runPromise = function runPromise(fn) {
debug2(' AFTER runPromise: ' + this.name + ' uid:' + currentUid + ' len:' + this._set.length + ' ' +
util.inspect(context));
}
this.exit(context);
throw err;
});
};
Expand Down
4 changes: 2 additions & 2 deletions context.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,20 @@ Namespace.prototype.runPromise = function runPromise(fn) {
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));
}
this.exit(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));
}
this.exit(context);
throw err;
});
};
Expand Down

0 comments on commit 3471d3a

Please sign in to comment.