Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(context): fixed runPromise mem leak and incorrect propagation #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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