Browse Source

Fix bug in process._tickCallback where callbacks can get abandoned.

Change process._tickCallback so that if a callback throws an error but
there are other callbacks after it, we indicate that
process._tickCallback needs to be ran again.

Currently, if a callback in process._tickCallback throws an error, and
that error is caught by an uncaughtException handler and
process.nextTick is never called again, then any other callbacks already
added to the nextTickQueue won't be called again.

Updated the next-tick-errors test to catch this scenario.
v0.7.4-release
Benjamin Thomas 15 years ago
committed by Ryan Dahl
parent
commit
cda1a38426
  1. 3
      src/node.js
  2. 11
      test/simple/test-next-tick-errors.js

3
src/node.js

@ -57,6 +57,9 @@ process._tickCallback = function () {
} }
catch(e) { catch(e) {
nextTickQueue.splice(0, i+1); nextTickQueue.splice(0, i+1);
if (i+1 < l) {
process._needTickCallback();
}
throw e; throw e;
} }

11
test/simple/test-next-tick-errors.js

@ -13,7 +13,8 @@ process.nextTick(function() {
}); });
// This nextTick function should remain in the queue when the first one // This nextTick function should remain in the queue when the first one
// is removed. // is removed. It should be called if the error in the first one is
// caught (which we do in this test).
process.nextTick(function() { process.nextTick(function() {
order.push('C'); order.push('C');
}); });
@ -22,12 +23,6 @@ process.addListener('uncaughtException', function() {
if (!exceptionHandled) { if (!exceptionHandled) {
exceptionHandled = true; exceptionHandled = true;
order.push('B'); order.push('B');
// We call process.nextTick here to make sure the nextTick queue is
// processed again. If everything goes according to plan then when the queue
// gets ran there will be two functions with this being the second.
process.nextTick(function() {
order.push('D');
});
} }
else { else {
// If we get here then the first process.nextTick got called twice // If we get here then the first process.nextTick got called twice
@ -36,6 +31,6 @@ process.addListener('uncaughtException', function() {
}); });
process.addListener('exit', function() { process.addListener('exit', function() {
assert.deepEqual(['A','B','C','D'], order); assert.deepEqual(['A','B','C'], order);
}); });

Loading…
Cancel
Save