Skip to content

fix: defer Wrappable destruction in SecondWeakCallback to a posted task - #50695

Merged
MarshallOfSound merged 1 commit into
42-x-yfrom
trop/42-x-y-bp-fix-defer-wrappable-destruction-in-secondweakcallback-to-a-posted-task-1775374698539
Apr 5, 2026
Merged

MarshallOfSound merged 1 commit into
42-x-yfrom
trop/42-x-y-bp-fix-defer-wrappable-destruction-in-secondweakcallback-to-a-posted-task-1775374698539

Conversation

@trop

@trop trop Bot commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Backport of #50688

See that PR for details.

Notes: Fixed an intermittent Invoke in DisallowJavascriptExecutionScope crash on application quit when a WebContents (or other JS-emitting native object) is garbage-collected during shutdown.

V8's second-pass weak callbacks run inside a
DisallowJavascriptExecutionScope: they may touch the V8 API but must
not invoke JS, directly or indirectly. Several Electron Wrappables
(WebContents in particular) emit JS events from their destructors,
so deleting synchronously inside SecondWeakCallback can crash with
"Invoke in DisallowJavascriptExecutionScope" when GC happens to
collect the JS wrapper during a foreground GC task — typically during
shutdown's uv_run drain after a leaked WebContentsView.

This was previously latent and timing-dependent (#47420,
#45416, podman-desktop/podman-desktop#12409). The
esbuild migration's keepNames option (which wraps every function/class
with an Object.defineProperty call) shifted heap layout enough to make
the spec/fixtures/crash-cases/webcontentsview-create-leak-exit case
reliably reproduce it on every run, giving a clean signal for the fix.

Both WrappableBase and DeprecatedWrappableBase SecondWeakCallback now
post the deletion via base::SequencedTaskRunner::GetCurrentDefault()
so the destructor (and any Emit it does) runs once V8 has left the GC
scope. Falls back to synchronous deletion if no task runner is
available (early/late process lifetime).

Fixes #47420.

Co-authored-by: Sam Attard <[email protected]>
@trop
trop Bot requested review from a team and MarshallOfSound April 5, 2026 07:38
@trop trop Bot added 42-x-y backport This is a backport PR semver/patch backwards-compatible bug fixes labels Apr 5, 2026
@MarshallOfSound
MarshallOfSound enabled auto-merge (squash) April 5, 2026 07:39
@MarshallOfSound
MarshallOfSound merged commit 2067d3a into 42-x-y Apr 5, 2026
70 of 71 checks passed
@MarshallOfSound
MarshallOfSound deleted the trop/42-x-y-bp-fix-defer-wrappable-destruction-in-secondweakcallback-to-a-posted-task-1775374698539 branch April 5, 2026 09:37
@release-clerk

release-clerk Bot commented Apr 5, 2026

Copy link
Copy Markdown

Release Notes Persisted

Fixed an intermittent Invoke in DisallowJavascriptExecutionScope crash on application quit when a WebContents (or other JS-emitting native object) is garbage-collected during shutdown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

42-x-y backport This is a backport PR semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant