From a5998152d5cdde0d34bcae6b2a9eb243f541fc4e Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 5 Jun 2019 23:27:42 +0200 Subject: [PATCH] src: fix off-by-one error in native SetImmediate Previously, the throwing callback would have been re-executed in case of an exception. This patch corrects the calculation to exclude the callback. PR-URL: https://github.com/nodejs/node/pull/28082 Fixes: https://github.com/nodejs/node/issues/26754 Reviewed-By: Michael Dawson Reviewed-By: Gabriel Schulhof Reviewed-By: James M Snell --- src/env.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/env.cc b/src/env.cc index f541188e73b24f..f0f4fc30688aad 100644 --- a/src/env.cc +++ b/src/env.cc @@ -641,6 +641,11 @@ void Environment::RunAndClearNativeImmediates() { if (!try_catch.HasTerminated()) FatalException(isolate(), try_catch); + // We are done with the current callback. Increase the counter so that + // the steps below make everything *after* the current item part of + // the new list. + it++; + // Bail out, remove the already executed callbacks from list // and set up a new TryCatch for the other pending callbacks. std::move_backward(it, list.end(), list.begin() + (list.end() - it));