Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
domain.dispose() before handle next(err)
  • Loading branch information
fengmk2 committed Mar 12, 2013
1 parent 631e31c commit 217714c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/connect-domain.js
Expand Up @@ -8,7 +8,11 @@ module.exports = function () {
reqDomain.dispose(); reqDomain.dispose();
}); });


reqDomain.on('error', next); reqDomain.on('error', function (err) {
// Once a domain is disposed, further errors from the emitters in that set will be ignored.
reqDomain.dispose();
next(err);
});


reqDomain.run(next); reqDomain.run(next);
}; };
Expand Down
19 changes: 18 additions & 1 deletion test/domain.test.js
Expand Up @@ -26,6 +26,15 @@ describe('domain.test.js', function () {
}); });
return; return;
} }
if (req.url === '/async_error_twice') {
setTimeout(function () {
ff.foo();
}, 100);
setTimeout(function () {
bar.bar();
}, 210);
return;
}
res.end(req.url); res.end(req.url);
}; };


Expand Down Expand Up @@ -60,9 +69,10 @@ describe('domain.test.js', function () {
before(function () { before(function () {
mochaHandler = process.listeners('uncaughtException').pop(); mochaHandler = process.listeners('uncaughtException').pop();
}); });
after(function () { after(function (done) {
// ...but be sure to re-enable mocha's error handler // ...but be sure to re-enable mocha's error handler
process.on('uncaughtException', mochaHandler); process.on('uncaughtException', mochaHandler);
setTimeout(done, 500);
}); });


it('should GET /async_error status 500', function (done) { it('should GET /async_error status 500', function (done) {
Expand All @@ -71,6 +81,13 @@ describe('domain.test.js', function () {
.expect('ff is not defined') .expect('ff is not defined')
.expect(500, done); .expect(500, done);
}); });

it('should GET /async_error_twice status 500', function (done) {
request(app)
.get('/async_error_twice')
.expect('ff is not defined')
.expect(500, done);
});
}); });


}); });

0 comments on commit 217714c

Please sign in to comment.