Skip to content

Commit 3471d3a

Browse files
committed
fix(context): fixed runPromise mem leak and incorrect propagation
1 parent 0ff594b commit 3471d3a

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

context-legacy.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,24 @@ Namespace.prototype.runPromise = function runPromise(fn) {
127127
this.enter(context);
128128

129129
let promise = fn(context);
130+
130131
if (!promise || !promise.then || !promise.catch) {
131132
throw new Error('fn must return a promise.');
132133
}
133134

134135
if (DEBUG_CLS_HOOKED) {
135136
debug2(' BEFORE runPromise: ' + this.name + ' uid:' + currentUid + ' len:' + this._set.length + ' ' +
136-
util.inspect(context));
137+
util.inspect(context));
137138
}
138139

140+
this.exit(context);
141+
139142
return promise
140143
.then(result => {
141144
if (DEBUG_CLS_HOOKED) {
142145
debug2(' AFTER runPromise: ' + this.name + ' uid:' + currentUid + ' len:' + this._set.length + ' ' +
143146
util.inspect(context));
144147
}
145-
this.exit(context);
146148
return result;
147149
})
148150
.catch(err => {
@@ -151,7 +153,6 @@ Namespace.prototype.runPromise = function runPromise(fn) {
151153
debug2(' AFTER runPromise: ' + this.name + ' uid:' + currentUid + ' len:' + this._set.length + ' ' +
152154
util.inspect(context));
153155
}
154-
this.exit(context);
155156
throw err;
156157
});
157158
};

context.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,20 @@ Namespace.prototype.runPromise = function runPromise(fn) {
138138
debug2('CONTEXT-runPromise BEFORE: (' + this.name + ') currentUid:' + currentUid + ' len:' + this._set.length + ' ' + util.inspect(context));
139139
}
140140

141+
this.exit(context);
142+
141143
return promise
142144
.then(result => {
143145
if (DEBUG_CLS_HOOKED) {
144146
debug2('CONTEXT-runPromise AFTER then: (' + this.name + ') currentUid:' + currentUid + ' len:' + this._set.length + ' ' + util.inspect(context));
145147
}
146-
this.exit(context);
147148
return result;
148149
})
149150
.catch(err => {
150151
err[ERROR_SYMBOL] = context;
151152
if (DEBUG_CLS_HOOKED) {
152153
debug2('CONTEXT-runPromise AFTER catch: (' + this.name + ') currentUid:' + currentUid + ' len:' + this._set.length + ' ' + util.inspect(context));
153154
}
154-
this.exit(context);
155155
throw err;
156156
});
157157
};

0 commit comments

Comments
 (0)