Skip to content

Commit

Permalink
src: use a higher limit in the NearHeapLimitCallback
Browse files Browse the repository at this point in the history
V8 requires the NearHeapLimitCallback to return a limit that's higher
than the initial one or otherwise it will crash.

PR-URL: nodejs#41041
Refs: nodejs#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]>
  • Loading branch information
joyeecheung authored and Linkgoron committed Jan 31, 2022
1 parent 6032fc3 commit 2c4c2b6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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. "
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2c4c2b6

Please sign in to comment.