Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

domain.dispose() before handle next(err)

  • Loading branch information...
commit 217714ca2da37ce06f0a64033978be7ff32172b4 1 parent 631e31c
@fengmk2 fengmk2 authored
Showing with 23 additions and 2 deletions.
  1. +5 −1 lib/connect-domain.js
  2. +18 −1 test/domain.test.js
View
6 lib/connect-domain.js
@@ -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);
};
View
19 test/domain.test.js
@@ -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);
};
@@ -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) {
@@ -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);
+ });
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.