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

domain.dispose() before next(err) #8

Merged
merged 1 commit into from Mar 12, 2013
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion lib/connect-domain.js
Expand Up @@ -8,7 +8,11 @@ module.exports = function () {
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);
};
Expand Down
19 changes: 18 additions & 1 deletion test/domain.test.js
Expand Up @@ -26,6 +26,15 @@ describe('domain.test.js', function () {
});
return;
}
if (req.url === '/async_error_twice') {
setTimeout(function () {
ff.foo();
}, 100);
setTimeout(function () {
bar.bar();
}, 210);
return;
}
res.end(req.url);
};

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

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(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);
});
});

});