This repository has been archived by the owner. It is now read-only.

setTimeout fails to run callback if an earlier callback throws an exception #2631

Jimbly opened this Issue Jan 28, 2012 · 5 comments


None yet
3 participants

Jimbly commented Jan 28, 2012

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);

bnoordhuis commented Jan 29, 2012

Confirmed. Probably non-trivial to fix due to how timers have been reworked in v0.5.


bnoordhuis commented Jan 29, 2012

Anyone feel like reviewing 01bcad9? Be forewarned that it's not pretty.

koichik commented Jan 30, 2012

@bnoordhuis - LGTM.


bnoordhuis commented Jan 30, 2012

Thanks, Koichi. Fixed in b221fe9. Thanks for the report, Jimb.

Jimbly commented Jan 30, 2012

Your welcome, thanks for the quick fix!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.