[Bug]: Electron window may go blank after several minutes when hidden and disabling backgroundThrottling #42378
Labels
30-x-y
31-x-y
32-x-y
bug 🪲
has-repro-gist
Issue can be reproduced with code at https://gist.github.com/
platform/windows
status/confirmed
A maintainer reproduced the bug or agreed with the feature
Preflight Checklist
Electron Version
30.0.0
What operating system are you using?
Windows
Operating System Version
Windows 10 & 11
What arch are you using?
x64
Last Known Working Electron version
22.0.0
Expected Behavior
The Electron window contents should not disappear after several minutes when using the background throttling feature.
Actual Behavior
Reproduce steps:
electronApp.disableBackgroundThrottling();
This reproduces on Windows, have not tried on other OSes.
Note: Resizing the window or minimizing/restoring will temporarily fix the behavior and show the contents, but after the 5-10 minute window the contents will go blank again.
Testcase Gist URL
https://gist.github.com/markh-discord/4d828931b38d5917e5c8e73101981a54
Additional Information
This appears to be a bug with the
disable_hidden.patch
:electron/patches/chromium/disable_hidden.patch
Line 44 in 7569d90
Note: When background throttling is enabled (default), the
disable_hidden_
state will befalse
.From the reproduce steps, when the window is minimized (which calls
RenderWidgetHostViewAura::HideImpl()
) the condition above passes and eventually calls into:https://chromium.googlesource.com/chromium/src.git/+/27caf432b8c27240dd42820a7c5e098374a91970/content/browser/renderer_host/render_widget_host_view_aura.cc#655
which calls:
https://chromium.googlesource.com/chromium/src.git/+/27caf432b8c27240dd42820a7c5e098374a91970/content/browser/renderer_host/delegated_frame_host.cc#141
The next step is to disable the background throttling, effectively setting
disable_hidden_
totrue
.This triggers the
RenderWidgetHostImpl::WasShown
since it's currently hidden and setsis_hidden_ = true
:electron/shell/browser/api/electron_api_web_contents.cc
Line 2285 in 7569d90
Note that at this point the window is still minimized and not visibly shown to the user.
The next step is then to restore the window, this then hits this code (linking to the patch here since that's effectively what it's running):
electron/patches/chromium/allow_disabling_blink_scheduler_throttling_per_renderview.patch
Line 63 in 791907f
This condition now fails because the
host_->is_hidden()
was toggled above totrue
, skipping the calls to:RenderWidgetHostViewBase::OnShowWithPageVisibility
RenderWidgetHostViewAura::NotifyHostAndDelegateOnWasShown
DelegatedFrameHost::WasShown
FrameEvictor::SetVisible(true)
Since this entire runtime path is skipped, the
FrameEvictor
attached to theDelegatedFrameHost
(which is attached to the RenderWidgetHost) believes it's still not visible.The
FrameEvictorManager
has a 5 minute timer where it will begin evicting frames it believes aren't seen:https://chromium.googlesource.com/chromium/src.git/+/27caf432b8c27240dd42820a7c5e098374a91970/components/viz/client/frame_eviction_manager.h#90
The timer gets setup here with the 5 minute delay: https://chromium.googlesource.com/chromium/src.git/+/27caf432b8c27240dd42820a7c5e098374a91970/components/viz/client/frame_eviction_manager.cc#88
Likely due to small timing differences after the timer runs, the 5 minutes hasn't quite been hit in the check here:
https://chromium.googlesource.com/chromium/src.git/+/27caf432b8c27240dd42820a7c5e098374a91970/components/viz/client/frame_eviction_manager.cc#183
So it must wait another 5 minutes before the timer ticks again, which usually results in the 10 minute wait needed to observe this problem.
We did not see this behavior in Electron 22, but noticed it in Electron 28. This doesn't seem to be a problem in Electron 22 since the FrameEvictor was disabled at that point in time and was enabled shortly after: https://chromium.googlesource.com/chromium/src.git/+/4fbc6d67f7ba71ed61bedac5a146d3d931aba4c1
The text was updated successfully, but these errors were encountered: