Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

domain: fix dispatch handing #3983

Closed
wants to merge 1 commit into from

1 participant

@AndreasMadsen

Should fix issue: #3982

I wasn't totally sure what the expected behavior in Domain.prototype.enter was, but this seams more likely.

Note: this is target 0.8 since it blocks a production application

@AndreasMadsen AndreasMadsen domain: fix dispatch handing
Fixes an issue where only one domain exists and that domain is either
dispatched or left
9f8664c
@AndreasMadsen

Have been running with this for some time, it dosn't really solve the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 8, 2012
  1. @AndreasMadsen

    domain: fix dispatch handing

    AndreasMadsen authored
    Fixes an issue where only one domain exists and that domain is either
    dispatched or left
This page is out of date. Refresh to see the latest.
Showing with 53 additions and 5 deletions.
  1. +12 −5 lib/domain.js
  2. +41 −0 test/simple/test-domain-active.js
View
17 lib/domain.js
@@ -51,15 +51,18 @@ exports.active = null;
process.on('uncaughtException', uncaughtHandler);
function uncaughtHandler(er) {
+ var active = exports.active;
+
// if there's an active domain, then handle this there.
// Note that if this error emission throws, then it'll just crash.
- if (exports.active && !exports.active._disposed) {
+ if (active && !active._disposed) {
util._extend(er, {
- domain: exports.active,
+ domain: active,
domain_thrown: true
});
- exports.active.emit('error', er);
- exports.active.exit();
+
+ active.emit('error', er);
+ active.exit();
} else if (process.listeners('uncaughtException').length === 1) {
// if there are other handlers, then they'll take care of it.
// but if not, then we need to crash now.
@@ -73,6 +76,7 @@ function Domain() {
EventEmitter.apply(this);
this.members = [];
+ this._disposed = false;
}
Domain.prototype.enter = function() {
@@ -91,7 +95,7 @@ Domain.prototype.exit = function() {
var d;
do {
d = stack.pop();
- } while (d && d !== this);
+ } while (d && d === this);
exports.active = stack[stack.length - 1];
process.domain = exports.active;
@@ -249,6 +253,9 @@ Domain.prototype.dispose = function() {
// kill the references so that they can be properly gc'ed.
this.members.length = 0;
+ // update exports.active
+ this.exit();
+
// finally, mark this domain as 'no longer relevant'
// so that it can't be entered or activated.
this._disposed = true;
View
41 test/simple/test-domain-active.js
@@ -0,0 +1,41 @@
+
+var domain = require('domain');
+var http = require('http');
+var assert = require('assert');
+var common = require('../common');
+
+var server = http.createServer(function (req, res) {
+ var d = domain.create();
+ d.add(req);
+ d.add(res);
+
+ d.run(function () {
+ d.on('error', function (err) {
+ d.dispose();
+ domainDisposed = true;
+ });
+ throw new Error('error in route');
+ });
+});
+
+var closeEmitted = false;
+var domainDisposed = false;
+
+server.listen(common.PORT, '127.0.0.1', function () {
+ var href = 'http://127.0.0.1:' + common.PORT;
+ var req = http.get(href, function () { });
+
+ req.once('error', function (err) {
+ // expect domain.active to be null or undefined
+ assert(!domain.active);
+
+ server.close(function () {
+ closeEmitted = true;
+ });
+ });
+});
+
+process.once('exit', function () {
+ assert(closeEmitted);
+ assert(domainDisposed);
+});
Something went wrong with that request. Please try again.