Skip to content

Commit

Permalink
fix; exit all manually entered NodeJS domains
Browse files Browse the repository at this point in the history
  • Loading branch information
aheckmann committed Dec 14, 2017
1 parent 5c0fe50 commit 771b32d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions library/modules/es6.promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var notify = function (promise, isReject) {
var resolve = reaction.resolve;
var reject = reaction.reject;
var domain = reaction.domain;
var result, then;
var result, then, exited;
try {
if (handler) {
if (!ok) {
Expand All @@ -63,8 +63,11 @@ var notify = function (promise, isReject) {
if (handler === true) result = value;
else {
if (domain) domain.enter();
result = handler(value);
if (domain) domain.exit();
result = handler(value); // may throw
if (domain) {
domain.exit();
exited = true;
}
}
if (result === reaction.promise) {
reject(TypeError('Promise-chain cycle'));
Expand All @@ -73,6 +76,7 @@ var notify = function (promise, isReject) {
} else resolve(result);
} else reject(value);
} catch (e) {
if (domain && !exited) domain.exit();
reject(e);
}
};
Expand Down
10 changes: 7 additions & 3 deletions modules/es6.promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var notify = function (promise, isReject) {
var resolve = reaction.resolve;
var reject = reaction.reject;
var domain = reaction.domain;
var result, then;
var result, then, exited;
try {
if (handler) {
if (!ok) {
Expand All @@ -63,8 +63,11 @@ var notify = function (promise, isReject) {
if (handler === true) result = value;
else {
if (domain) domain.enter();
result = handler(value);
if (domain) domain.exit();
result = handler(value); // may throw
if (domain) {
domain.exit();
exited = true;
}
}
if (result === reaction.promise) {
reject(TypeError('Promise-chain cycle'));
Expand All @@ -73,6 +76,7 @@ var notify = function (promise, isReject) {
} else resolve(result);
} else reject(value);
} catch (e) {
if (domain && !exited) domain.exit();
reject(e);
}
};
Expand Down

0 comments on commit 771b32d

Please sign in to comment.