Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
RFC: Track implicit domain members
Problem: When creating streams inside of a domain, Domain#dispose() will
not clean them up.

This patch demonstrates this problem using a test case, and provides a
possible fix by also adding implicit domain members to the domain.

Considering that I don't understand the design decisions that went into
only tracking explicit members at this point, this patch should be
considered as a request for comment on the current behavior / to start a
discussion on improving it.
  • Loading branch information
felixge committed Jun 27, 2012
1 parent 0cdeb8e commit 16cbec0
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/events.js
Expand Up @@ -28,6 +28,7 @@ function EventEmitter() {
domain = domain || require('domain'); domain = domain || require('domain');
if (domain.active && !(this instanceof domain.Domain)) { if (domain.active && !(this instanceof domain.Domain)) {
this.domain = domain.active; this.domain = domain.active;
this.domain.members.push(this);
} }
} }
} }
Expand Down
69 changes: 69 additions & 0 deletions test/simple/test-domain-run-bug.js
@@ -0,0 +1,69 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var assert = require('assert');
var common = require('../common.js');
var net = require('net');
var domain = require('domain');

console.log('starting test ...');

var connections =0;
var server = net.createServer(function(socket) {
connections++;

socket.on('end', function() {
connections--;

if (connections === 0) {
server.close();
}
});

socket.write('hi');
});

server.listen(common.PORT, function() {
var d = domain.create();

d.on('error', function(err) {
assert.equal(d.members.length, 1);

console.log('caught domain exception: %s', err.message);
d.dispose();
});


d.run(function() {
var socket = net.createConnection(common.PORT);

socket.setEncoding('utf-8');

socket.on('data', function(data) {
console.log('received data from server: %s', data);
throw new Error('Boom!');
});
});
});

process.on('exit', function() {
assert.equal(connections, 0);
});

0 comments on commit 16cbec0

Please sign in to comment.