From 6f0ec9835a44b9605d220c177e698012d6a37f14 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 1 Dec 2021 00:58:16 +0800 Subject: [PATCH] src: use a higher limit in the NearHeapLimitCallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit V8 requires the NearHeapLimitCallback to return a limit that's higher than the initial one or otherwise it will crash. PR-URL: https://github.com/nodejs/node/pull/41041 Refs: https://github.com/nodejs/node/pull/41013 Reviewed-By: Michaël Zasso Reviewed-By: Tobias Nießen Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- src/env.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/env.cc b/src/env.cc index 2cb2dccdf32ba4..bbc3f6a9a41d44 100644 --- a/src/env.cc +++ b/src/env.cc @@ -1577,7 +1577,7 @@ size_t Environment::NearHeapLimitCallback(void* data, // may eventually crash with this new limit - effectively raising // the heap limit to the new one. if (env->is_processing_heap_limit_callback_) { - size_t new_limit = initial_heap_limit + max_young_gen_size; + size_t new_limit = current_heap_limit + max_young_gen_size; Debug(env, DebugCategory::DIAGNOSTICS, "Not generating snapshots in nested callback. " @@ -1595,7 +1595,9 @@ size_t Environment::NearHeapLimitCallback(void* data, "Not generating snapshots because it's too risky.\n"); env->isolate()->RemoveNearHeapLimitCallback(NearHeapLimitCallback, initial_heap_limit); - return current_heap_limit; + // The new limit must be higher than current_heap_limit or V8 might + // crash. + return current_heap_limit + 1; } // Take the snapshot synchronously. @@ -1631,7 +1633,10 @@ size_t Environment::NearHeapLimitCallback(void* data, env->isolate()->AutomaticallyRestoreInitialHeapLimit(0.95); env->is_processing_heap_limit_callback_ = false; - return initial_heap_limit; + + // The new limit must be higher than current_heap_limit or V8 might + // crash. + return current_heap_limit + 1; } inline size_t Environment::SelfSize() const {