Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

domain: Wrap destroy methods in a try/catch

  • Loading branch information...
isaacs committed Apr 13, 2012
1 parent 7b3fd2e commit 7aeec9df394883d077a054b8412cb3fca4a73171
Showing with 15 additions and 16 deletions.
  1. +15 −16 lib/domain.js
@@ -24,6 +24,9 @@ var events = require('events');
var EventEmitter = events.EventEmitter;
var inherits = util.inherits;

// methods that are called when trying to shut down expliclitly bound EEs
var endMethods = [ 'end', 'abort', 'destroy', 'destroySoon' ];

// communicate with events module, but don't require that
// module to have to load this one, since this module has
// a few side effects.
@@ -198,22 +201,18 @@ Domain.prototype.dispose = function() {
m.on('error', function() {});
}

// call all final methods.
if (typeof m.end === 'function') {
m.end();
}
if (typeof m.abort === 'function') {
m.abort();
}
if (typeof m.close === 'function') {
m.close();
}
if (typeof m.destroy === 'function') {
m.destroy();
}
if (typeof m.destroySoon === 'function') {
m.destroySoon();
}
// Be careful!
// By definition, we're likely in error-ridden territory here,
// so it's quite possible that calling some of these methods
// might cause additional exceptions to be thrown.
endMethods.forEach(function(method) {
if (typeof m[method] === 'function') {
try {
m[method]();
} catch (er) {}
}
});

});

// remove from parent domain, if there is one.

0 comments on commit 7aeec9d

Please sign in to comment.
You can’t perform that action at this time.