Skip to content

Commit

Permalink
fix: workaround for popout window crash when separate environment has…
Browse files Browse the repository at this point in the history
… a task that could call into JS prepared on the shared uv_loop

Patch-Filename: fix_workaround_for_popout_window_crash_when_separate_environment_has.patch
  • Loading branch information
markh-discord authored and CI Bot committed Jan 17, 2024
1 parent 1c71ae1 commit e562414
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions shell/renderer/electron_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,27 @@ void ElectronRendererClient::WillReleaseScriptContext(
DCHECK_EQ(microtask_queue->GetMicrotasksScopeDepth(), 0);
microtask_queue->set_microtasks_policy(v8::MicrotasksPolicy::kExplicit);

// Hack workaround(markh): Mark all other environments to _not_ call into js
// to avoid problems with the shared isolate and uv_loop structures shared
// by this same environment we're trying to cleanup.
// During this environment cleanup the uv_loop is run, where possible tasks
// from other environments that share the loop might also try to run. Our
// call stack will have setup v8 to disable JS, so we need to signal to the
// other environments not to attempt to run any JS.
// The downside here is that any of those tasks that happen to be present in
// the uv_loop at the time will effectively no-op and get dropped.
// Note: We re-enable this flag after cleanup has completed below.
for (const std::shared_ptr<node::Environment>& otherEnv : environments_) {
otherEnv->set_can_call_into_js(false);
}

environments_.erase(iter);

// Hack workaround(markh): Re-setup JS callbacks for other environments
for (const std::shared_ptr<node::Environment>& otherEnv : environments_) {
otherEnv->set_can_call_into_js(true);
}

microtask_queue->set_microtasks_policy(old_policy);

// ElectronBindings is tracking node environments.
Expand Down

0 comments on commit e562414

Please sign in to comment.