Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

domain: Wrap destroy methods in a try/catch

  • Loading branch information...
commit 7aeec9df394883d077a054b8412cb3fca4a73171 1 parent 7b3fd2e
@isaacs isaacs authored
Showing with 15 additions and 16 deletions.
  1. +15 −16 lib/domain.js
View
31 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.
Please sign in to comment.
Something went wrong with that request. Please try again.