From 6eb4d1d15ca8d2b82cf9db99d56633357ccc3320 Mon Sep 17 00:00:00 2001 From: Greg Brail Date: Tue, 28 Jan 2014 17:36:22 -0800 Subject: timer: don't reschedule timer bucket in a domain If two timers run on the same tick, and the first timer uses a domain, and then catches an exception and disposes of the domain, then the second timer never runs. (And even if the first timer does not dispose of the domain, the second timer could run under the wrong domain.) This happens because timer.js uses "process.nextTick()" to schedule continued processing of the timers for that tick. However, there was an exception inside a domain, then "process.nextTick()" runs under the domain of the first timer function, and will do nothing if the domain has been disposed. To avoid this, we temporarily save the value of "process.domain" before calling nextTick so that it does not run inside any domain. --- lib/timers.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib') diff --git a/lib/timers.js b/lib/timers.js index 076503e601..db4f5bd972 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -113,9 +113,15 @@ function listOnTimeout() { threw = false; } finally { if (threw) { + // We need to continue processing after domain error handling + // is complete, but not by using whatever domain was left over + // when the timeout threw its exception. + var oldDomain = process.domain; + process.domain = null; process.nextTick(function() { list.ontimeout(); }); + process.domain = oldDomain; } } } -- cgit v1.2.3