Skip to content

Commit 6f0ec98

Browse files
joyeecheungdanielleadams
authored andcommitted
src: use a higher limit in the NearHeapLimitCallback
V8 requires the NearHeapLimitCallback to return a limit that's higher than the initial one or otherwise it will crash. PR-URL: #41041 Refs: #41013 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent b353ded commit 6f0ec98

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/env.cc

+8-3
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,7 @@ size_t Environment::NearHeapLimitCallback(void* data,
15771577
// may eventually crash with this new limit - effectively raising
15781578
// the heap limit to the new one.
15791579
if (env->is_processing_heap_limit_callback_) {
1580-
size_t new_limit = initial_heap_limit + max_young_gen_size;
1580+
size_t new_limit = current_heap_limit + max_young_gen_size;
15811581
Debug(env,
15821582
DebugCategory::DIAGNOSTICS,
15831583
"Not generating snapshots in nested callback. "
@@ -1595,7 +1595,9 @@ size_t Environment::NearHeapLimitCallback(void* data,
15951595
"Not generating snapshots because it's too risky.\n");
15961596
env->isolate()->RemoveNearHeapLimitCallback(NearHeapLimitCallback,
15971597
initial_heap_limit);
1598-
return current_heap_limit;
1598+
// The new limit must be higher than current_heap_limit or V8 might
1599+
// crash.
1600+
return current_heap_limit + 1;
15991601
}
16001602

16011603
// Take the snapshot synchronously.
@@ -1631,7 +1633,10 @@ size_t Environment::NearHeapLimitCallback(void* data,
16311633
env->isolate()->AutomaticallyRestoreInitialHeapLimit(0.95);
16321634

16331635
env->is_processing_heap_limit_callback_ = false;
1634-
return initial_heap_limit;
1636+
1637+
// The new limit must be higher than current_heap_limit or V8 might
1638+
// crash.
1639+
return current_heap_limit + 1;
16351640
}
16361641

16371642
inline size_t Environment::SelfSize() const {

0 commit comments

Comments
 (0)