Skip to content

[Bug]: Renderer of a cross-site iframe with a pagehide handler outlives app.quit() (macOS, busy machine) #56034

Backlog

Description

@peteygao

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for a bug report that matches the one I want to file, without success.

Electron Version

43.8.4

What operating system(s) are you using?

macOS

Operating System Version

macOS 26.6.2

What arch are you using?

arm64 (including Apple Silicon)

Last Known Working Electron version

No response

Does the issue also appear in Chromium / Google Chrome?

Not tested. Chrome calls FastShutdownIfPossible on each render process host as its shutdown starts, so it should not.

Expected Behavior

Every renderer process is ended with the app at quit.

Actual Behavior

After a clean quit (exit code 0) a renderer process stays alive with parent 1, for minutes on a busy Mac. It keeps
the app's stdout and stderr pipes open, so a parent that waits for the child's close event (Node's child_process, Playwright's
electronApplication.close()) waits as long.

Testcase Gist URL

No response

Additional Information

Why. For a subframe with unload handlers RenderFrameHostImpl::DeleteRenderFrame calls
RenderProcessHostImpl::DelayProcessShutdown, which holds shutdown_delay_ref_count_ until a delayed UI-thread task. Browser::Shutdown
quits the main run loop first, so that task never runs, and the later DisableRefCounts › Cleanup posts a DeleteSoon to a loop that no
longer runs. The RenderProcessHostImpl is never destroyed, so ChildProcessLauncher never sends the renderer SIGTERM and SIGKILL.
The renderer must notice the lost channel by itself, and a hidden page's renderer on macOS runs every thread at priority 4
(TASK_BACKGROUND_APPLICATION with the suppression policy), so on a busy machine it does not get to.

How to see it, made certain. A window whose page holds <iframe src="http://127.0.0.1:PORT/">, the framed page running
addEventListener('pagehide', () => {}). Send the iframe's renderer SIGSTOP, then quit. The app exits with code 0 and the renderer
stays (3 of 3). Without the pagehide listener it is ended with the app (0 of 3 left).

Asked for. At quit, end every remaining RenderProcessHost's process before the main loop ends (Chrome calls
FastShutdownIfPossible on each host as its shutdown starts), or run the loop until the pending DeleteSoon tasks have run.

Measured on an Apple M1 Pro (8 performance cores, 2 efficiency cores), Chromium 150.0.7871.250.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions