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

Adding of Node.JS Domains to Error Handling Broke Simpleworkflow #88

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 13 additions & 9 deletions lib/sequential_executor.js
Expand Up @@ -29,10 +29,10 @@ var domain;
AWS.SequentialExecutor = AWS.util.inherit({

constructor: function SequentialExecutor() {
this.domain = null;
this._domain = null;
if (require('events').usingDomains) {
domain = require('domain');
if (domain.active) this.domain = domain.active;
if (domain.active) this._domain = domain.active;
}
this._events = {};
},
Expand Down Expand Up @@ -92,7 +92,8 @@ AWS.SequentialExecutor = AWS.util.inherit({
*/
emit: function emit(eventName, eventArgs, doneCallback) {
if (!doneCallback) doneCallback = this.unhandledErrorCallback;
if (this.domain) this.domain.enter();
if (this._domain && (this._domain instanceof require('domain').Domain))
this._domain.enter();

var listeners = this.listeners(eventName);
var count = listeners.length;
Expand All @@ -106,7 +107,8 @@ AWS.SequentialExecutor = AWS.util.inherit({
callListeners: function callListeners(listeners, args, doneCallback) {
if (listeners.length === 0) {
doneCallback.call(this);
if (this.domain) this.domain.exit();
if (this._domain && (this._domain instanceof require('domain').Domain))
this._domain.exit();
} else {
var listener = listeners.shift();
if (listener.async) {
Expand All @@ -115,7 +117,8 @@ AWS.SequentialExecutor = AWS.util.inherit({
var callNextListener = function(err) {
if (err) {
doneCallback.call(this, err);
if (this.domain) this.domain.exit();
if (this._domain && (this._domain instanceof require('domain').Domain))
this._domain.exit();
} else {
this.callListeners(listeners, args, doneCallback);
}
Expand All @@ -130,7 +133,8 @@ AWS.SequentialExecutor = AWS.util.inherit({
this.callListeners(listeners, args, doneCallback);
} catch (err) {
doneCallback.call(this, err);
if (this.domain) this.domain.exit();
if (this._domain && (this._domain instanceof require('domain').Domain))
this._domain.exit();
}

}
Expand Down Expand Up @@ -248,11 +252,11 @@ AWS.SequentialExecutor = AWS.util.inherit({
*/
unhandledErrorCallback: function unhandledErrorCallback(err) {
if (err) {
if (this.domain) {
if (this._domain && (this._domain instanceof require('domain').Domain)) {
err.domainEmitter = this;
err.domain = this.domain;
err.domain = this._domain;
err.domainThrown = false;
this.domain.emit('error', err);
this._domain.emit('error', err);
} else {
throw err;
}
Expand Down