Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

domain.dispose() before handle next(err)

  • Loading branch information...
commit 217714ca2da37ce06f0a64033978be7ff32172b4 1 parent 631e31c
fengmk2 authored March 04, 2013
6  lib/connect-domain.js
@@ -8,7 +8,11 @@ module.exports = function () {
8 8
 			reqDomain.dispose();
9 9
 		});
10 10
 
11  
-		reqDomain.on('error', next);
  11
+		reqDomain.on('error', function (err) {
  12
+			// Once a domain is disposed, further errors from the emitters in that set will be ignored.
  13
+			reqDomain.dispose();
  14
+			next(err);
  15
+		});
12 16
 
13 17
 		reqDomain.run(next);
14 18
 	};
19  test/domain.test.js
@@ -26,6 +26,15 @@ describe('domain.test.js', function () {
26 26
       });
27 27
       return;
28 28
     }
  29
+    if (req.url === '/async_error_twice') {
  30
+      setTimeout(function () {
  31
+        ff.foo();
  32
+      }, 100);
  33
+      setTimeout(function () {
  34
+        bar.bar();
  35
+      }, 210);
  36
+      return;
  37
+    }
29 38
     res.end(req.url);
30 39
   };
31 40
 
@@ -60,9 +69,10 @@ describe('domain.test.js', function () {
60 69
     before(function () {
61 70
       mochaHandler = process.listeners('uncaughtException').pop();
62 71
     });
63  
-    after(function () {
  72
+    after(function (done) {
64 73
       // ...but be sure to re-enable mocha's error handler
65 74
       process.on('uncaughtException', mochaHandler);
  75
+      setTimeout(done, 500);
66 76
     });
67 77
 
68 78
     it('should GET /async_error status 500', function (done) {
@@ -71,6 +81,13 @@ describe('domain.test.js', function () {
71 81
       .expect('ff is not defined')
72 82
       .expect(500, done);
73 83
     });
  84
+
  85
+    it('should GET /async_error_twice status 500', function (done) {
  86
+      request(app)
  87
+      .get('/async_error_twice')
  88
+      .expect('ff is not defined')
  89
+      .expect(500, done);
  90
+    });
74 91
   });
75 92
 
76 93
 });

0 notes on commit 217714c

Please sign in to comment.
Something went wrong with that request. Please try again.