Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hang/blank window after reload window with running terminal processes #127421

Closed
egamma opened this issue Jun 29, 2021 · 15 comments
Closed

Hang/blank window after reload window with running terminal processes #127421

egamma opened this issue Jun 29, 2021 · 15 comments
Assignees
Labels
electron Issues and items related to Electron fixed-in-electron-13 Issues fixed with Electron 13.x update freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues
Milestone

Comments

@egamma
Copy link
Member

egamma commented Jun 29, 2021

Testing #127195
On OS X Version 11.4

  • open vscode folder
  • open a terminal
  • in the terminal execute the following script
sh
while true
do
date
sleep 1
done

image

  • execute Reload window

The command hangs, you see a blank window and cannot open the developer tools (sry for the unhelpful screenshot)
image

Closing the blank window and opening the vscode folder in a new window reconnects to the running process.

Repro behaviour:

  • I can reproduce this behaviour about every 2-10 times in the above setup with open vscode folder after waiting a couple of seconds.
  • I was not able to reproduce the behaviour when I have a simple test folder containing a couple files open.
  • I've failed to reproduce the reload hang when there is no open terminal.
  • I've failed to reproduce the reload hang in a remote setup using Remote Containers.

@bpasero any suggestion for how to collect more diagnostic information when in this state?

@egamma egamma changed the title Hang/blank window after reload window Hang/blank window after reload window with running terminal processes Jun 29, 2021
@Tyriar Tyriar added this to the June 2021 milestone Jun 29, 2021
@Tyriar Tyriar added bug Issue identified by VS Code Team member as probable bug terminal Integrated terminal issues labels Jun 29, 2021
@bpasero
Copy link
Member

bpasero commented Jun 29, 2021

code-insiders --verbose --open-devtools

@egamma
Copy link
Member Author

egamma commented Jun 29, 2021

Can be reproduced with no active terminals.

@egamma egamma assigned bpasero and unassigned Tyriar and meganrogge Jun 29, 2021
@deepak1556 deepak1556 self-assigned this Jun 29, 2021
@bpasero bpasero added freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues important Issue identified as high-priority labels Jun 29, 2021
@egamma
Copy link
Member Author

egamma commented Jun 29, 2021

@bpasero
Copy link
Member

bpasero commented Jun 29, 2021

My findings:

  • this reproduces in stable too and I can reproduce running out of sources
  • this is more likely to happen with a large workspace state DB (Erich's is >30 MB) and would explain why no user reported this so far
  • this reproduces only on reload but I would think it might reproduce even on normal load as well
  • the hang happens because we wait for a IPC message from the preload script to return from the main process [1] and this never returns
  • the IPC channel exists on the main side and is implemented in [2] (it is the same channel that the window talks to when loading initially)

[1]

configuration = await ipcRenderer.invoke(windowConfigIpcChannel);

[2]

@deepak1556 deepak1556 removed the terminal Integrated terminal issues label Jun 30, 2021
@deepak1556
Copy link
Collaborator

After looking at the mojom traces, the problem turned out to be quite simple. The message pipe used by ipcRenderer module are bound to the lifetime of a RenderFrame as the corresponding interfaces exposed from the browser process are tied to RenderFrameHost. When a renderer navigates to a new document, during the commit stage of navigation (it is when the client has received response from the server), the render process will reset the browser interface connection https://source.chromium.org/chromium/chromium/src/+/main:content/renderer/render_frame_impl.cc;l=3797-3812 so that old message pipe from previous document is not used to get the interfaces.

In normal cases, this above reset happens before preload script executes so there should be no issues. But in this bug, what happens is that on reload the sqlite connection reestablishment is delaying the navigation lifecycle causing the preload script to run before the navigation has committed. This now becomes a race condition where the ipc.invoke calls are dropped because the message pipe they were bound to was destroyed later by the navigation commit stage.

chrometrace.zip

Attaching chrometrace that will have two RenderFrameImpl::didCommitProvisionalLoad callstacks, the first one is in the renderer with pid 886 which does the initial document load. If you close up around 1540ms, you will see that the electron::mojom::ElectronBrowser::Invoke calls related to our vscode:<uuid> used for config retrieval will be after the commit stage has made a call to blink::mojom::BrowserInterfaceBroker::GetInterface.

Screen Shot 2021-06-30 at 11 20 28 PM

The second one is in renderer with pid 912, this is the renderer used after the reload call has been issued (a new render process because we don't use process reuse yet). Again close up around 9242ms, you will see that the above electron ipc call will happen before the render commit stage resets the call to BrowserInterfaceBroker

Screen Shot 2021-06-30 at 11 10 54 PM

@deepak1556
Copy link
Collaborator

As to why the sqlite connection messes with the navigation cycle even though it is async is yet to be investigated. FWIW we should ensure in Electron that preload script is loaded only after navigation commits so that the interface broker expectation set by chromium is respected.

@bpasero
Copy link
Member

bpasero commented Jun 30, 2021

@deepak1556 Great findings. Since this seems to be so specific to window reload, should I proceed with pushing a change to not warm up the SQLite connection on reload?

@deepak1556
Copy link
Collaborator

Thinking about that, if you can delay the ipc calls in the preload till https://github.com/electron/electron/blob/main/docs/api/web-contents.md#event-did-frame-navigate then it is guaranteed that we are making the calls after the renderer has navigated. The above event is the main process equivalent of navigation commit.

@bpasero
Copy link
Member

bpasero commented Jun 30, 2021

I am a little bit reluctant pushing a change like that so late in the endgame...

@deepak1556
Copy link
Collaborator

Oh yeah for the endgame, sqlite change sounds good.

@bpasero
Copy link
Member

bpasero commented Jun 30, 2021

@deepak1556 please take a look at b67f4cc. This should cover the reload scenario at least. Arguably I think it could happen as well when changing workspaces on an existing window but since no user complained so far, I suggest we do the real fix in Electron in July if possible.

@bpasero bpasero modified the milestones: June 2021, July 2021 Jun 30, 2021
@bpasero bpasero added electron Issues and items related to Electron and removed important Issue identified as high-priority labels Jun 30, 2021
@bpasero
Copy link
Member

bpasero commented Jul 7, 2021

I pushed another change to also skip the sqlite init when loading a window that was loaded before, leaving this case to only warm up sqlite on the very first opening of a window.

Deepak to investigate whether a fix in Electron:

  • is low hanging
  • does not have perf implications

Otherwise I suggest to close for now unless lots of others see this in their Electron use.

@deepak1556
Copy link
Collaborator

With Electron 13 update and reverting the above sqlite workarounds, I am no longer able to repro the issue. Preload script is executing only after the IPC broker connection is reset.

@bpasero I will leave this issue open incase you want to revert the sqlite workarounds otherwise feel free to close it. Thanks!

@deepak1556 deepak1556 assigned bpasero and unassigned deepak1556 Jul 15, 2021
@deepak1556 deepak1556 added the fixed-in-electron-13 Issues fixed with Electron 13.x update label Jul 15, 2021
@isidorn
Copy link
Contributor

isidorn commented Jul 29, 2021

Ben is on vacation, so moving this out to August so he can decide what to do in debt week. Nothing for endgame.

@bpasero
Copy link
Member

bpasero commented Aug 4, 2021

I was not able to reproduce either after removing my workaround, thus going with it 👍

@bpasero bpasero closed this as completed Aug 4, 2021
@bpasero bpasero removed the bug Issue identified by VS Code Team member as probable bug label Aug 18, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Sep 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
electron Issues and items related to Electron fixed-in-electron-13 Issues fixed with Electron 13.x update freeze-slow-crash-leak VS Code crashing, performance, freeze and memory leak issues
Projects
Archived in project
Development

No branches or pull requests

6 participants