joyent/node — Issue #2631: setTimeout fails to run callback if an earlier callback throws an exception
Author: Jimbly
Created: 2012-01-28 23:05:51+00:00
State: open

If you set a process uncaughtException handler, and then queue two callbacks with setTimeout with the same timeout, and the first one throws an exception, the second one is never called. This worked fine on Node 0.4 and appears to be broken on at least Node 0.6.6 and 0.6.9.

This code trivially reproduces the bug:

process.on('uncaughtException', function(err) {
console.log('Uncaught exception ' + err);
});

setTimeout(function() {
// called fine, but breaks any other timeouts of the same delay, regardless of when they were queued
console.log('first callback');
throw new Error('foo');
}, 100);

var called = false;
setTimeout(function() {
// never gets called in Node 0.6
console.log('second callback');
called = true;
}, 100);

// timeout of anything other than the earlier value (100) gets called fine
setTimeout(function() {
if (!called) {
console.log('Test FAILED');
} else {
console.log('Test PASSED');
}
}, 1000);