Skip to content

refactor: allocate api::Session on cpp heap - #48141

Merged
deepak1556 merged 1 commit into
mainfrom
robo/make_api_session_gin_wrappable
Aug 25, 2025
Merged

deepak1556 merged 1 commit into
mainfrom
robo/make_api_session_gin_wrappable

Conversation

@deepak1556

Copy link
Copy Markdown
Member

Description of Change

Part of #47922

api::Session is persisted for the lifetime of the process and gets destroyed via CleanupAtExit hook that runs before the microtask runner destruction. The following changes are made in this PR,

  1. Allocate a cpp heap pointer tag gin::kElectronSession that will be used to verify the wrapper object
  2. gin::Pinnable<T> is replaced with gin_helper::SelfKeepAlive<T> which retains a persistent pointer to the on-heap object
  3. base::WeakPtr<Session> that is used to associate with a BrowserContext is now replaced with gin::WeakCell<Session>
  4. We don't yet destroy JavascriptEnvironment as part of the platform destruction
    // Destroy node platform after all destructors_ are executed, as they may
    // invoke Node/V8 APIs inside them.
    node_env_->set_trace_sync_io(false);
    js_env_->DestroyMicrotasksRunner();
    node::Stop(node_env_.get(), node::StopFlags::kDoNotTerminateIsolate);
    node_bindings_->set_uv_env(nullptr);
    node_env_.reset();
    , so we cannot hook into any isolate or context observers to invalidate the weak cell and clear the persistent self pointer at the right time. There is context lifecycle observer being ported to gin from blink in https://chromium-review.googlesource.com/c/chromium/src/+/6832158, however we still need our js_env_ to be destroyed earlier but that cannot happen till we finish the transition of all wrappable to cpp heap. As a temporary transition, there is now a gin::PerIsolateData::DisposeObserver::OnBeforeMicrotasksRunnerDispose hook that will help maintain the current lifetime.

Release Notes

Notes: session module backing C++ object is now managed by v8

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Aug 20, 2025
@deepak1556
deepak1556 force-pushed the robo/make_api_session_gin_wrappable branch 2 times, most recently from 0e4097b to ed7b41d Compare August 21, 2025 16:44
@deepak1556
deepak1556 marked this pull request as ready for review August 21, 2025 16:45
@deepak1556
deepak1556 requested a review from a team as a code owner August 21, 2025 16:45
@deepak1556
deepak1556 marked this pull request as draft August 21, 2025 16:54
@deepak1556
deepak1556 force-pushed the robo/make_api_session_gin_wrappable branch from ed7b41d to 37ce525 Compare August 21, 2025 17:28
@deepak1556
deepak1556 marked this pull request as ready for review August 22, 2025 03:56
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Aug 23, 2025
@deepak1556
deepak1556 merged commit 3ccb1bc into main Aug 25, 2025
@deepak1556
deepak1556 deleted the robo/make_api_session_gin_wrappable branch August 25, 2025 09:52
@release-clerk

release-clerk Bot commented Aug 25, 2025

Copy link
Copy Markdown

Release Notes Persisted

session module backing C++ object is now managed by v8

dodolalorc pushed a commit to dodolalorc/electron that referenced this pull request Sep 11, 2025
kigh-ota pushed a commit to kigh-ota/electron that referenced this pull request Sep 30, 2025
@ckerr ckerr mentioned this pull request Apr 11, 2026
2 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants