Skip to content

Instantly share code, notes, and snippets.

@isaacs isaacs/gist:4773339
Created Feb 12, 2013

Embed
What would you like to do?
diff --git a/src/node.js b/src/node.js
index 62f5fa8..af745a0 100644
--- a/src/node.js
+++ b/src/node.js
@@ -157,6 +157,8 @@
});
}
}
+
+ process._needTickCallback();
}
startup.globalVariables = function() {
@@ -263,11 +265,17 @@
// since that means that we'll exit the process, emit the 'exit' event
if (!caught) {
try {
- process.emit('exit', 1);
+ if (!process._exiting) {
+ process._exiting = true;
+ process.emit('exit', 1);
+ }
} catch (er) {
// nothing to be done about it at this point.
}
}
+ // if we handled an error, then make sure any ticks get processed
+ if (caught)
+ process._needTickCallback();
return caught;
};
};
@@ -368,9 +376,8 @@
nextTickQueue.splice(0, nextTickIndex);
nextTickIndex = 0;
inTick = false;
- if (nextTickQueue.length) {
+ if (nextTickQueue.length)
process._needTickCallback();
- }
}
function maxTickWarn() {
@@ -449,17 +456,17 @@
process.nextTick = function(callback) {
// on the way out, don't bother.
// it won't get fired anyway.
- if (process._exiting) return;
+ if (process._exiting)
+ return;
- if (tickDepth >= process.maxTickDepth)
+ if (tickDepth >= process.maxTickDepth) {
maxTickWarn();
+ process._needTickCallback();
+ }
var tock = { callback: callback };
if (process.domain) tock.domain = process.domain;
nextTickQueue.push(tock);
- if (nextTickQueue.length) {
- process._needTickCallback();
- }
};
};
diff --git a/test/simple/test-timers-uncaught-exception.js b/test/simple/test-timers-uncaught-exception.js
index 0d2f488..1e7c157 100644
--- a/test/simple/test-timers-uncaught-exception.js
+++ b/test/simple/test-timers-uncaught-exception.js
@@ -26,25 +26,33 @@ var exceptions = 0;
var timer1 = 0;
var timer2 = 0;
+console.error('set first timer');
// the first timer throws...
setTimeout(function() {
+ console.error('first timer');
timer1++;
throw new Error('BAM!');
}, 100);
// ...but the second one should still run
+console.error('set second timer');
setTimeout(function() {
+ console.error('second timer');
assert.equal(timer1, 1);
timer2++;
}, 100);
function uncaughtException(err) {
+ console.error('uncaught handler');
assert.equal(err.message, 'BAM!');
exceptions++;
}
process.on('uncaughtException', uncaughtException);
+var exited = false;
process.on('exit', function() {
+ assert(!exited);
+ exited = true;
process.removeListener('uncaughtException', uncaughtException);
assert.equal(exceptions, 1);
assert.equal(timer1, 1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.