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

fix: destroy WebContents synchronously on shutdown #15541

Merged
merged 1 commit into from Nov 8, 2018

Conversation

zcbenz
Copy link
Member

@zcbenz zcbenz commented Nov 2, 2018

Description of Change

Destroying WebContents asynchronously on shutdown may delay the destroying task after the shutdown task, resulting in an assertion in ResourceDispatcherHostImpl::OnShutdown.

This PR destroys WebContents synchronously on shutdown, so we can fix #15133 without breaking #8930.

I have also added notes for DestroyWebContents on how to use it correctly.

Checklist

  • PR description included and stakeholders cc'd
  • npm test passes
  • tests are changed or added
  • relevant documentation is changed or added
  • PR title follows semantic commit guidelines

Release Notes

Notes: Fix crash on exit when using BrowserView.

@zcbenz zcbenz requested review from a team November 2, 2018 05:30
@zcbenz zcbenz force-pushed the destroy-webcontents-sync branch 2 times, most recently from 9f28853 to 7416c2e Compare November 2, 2018 08:34
@zcbenz
Copy link
Member Author

zcbenz commented Nov 2, 2018

This PR has accidentally revealed a crash in other place:

* thread #1: tid = 0x83cc89, 0x000000010122ee88 Electron Framework`::GuestCurrentlyAudibleCallback() + 8 at browser_plugin_embedder.cc:200, name = 'CrBrowserMain', queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x190)
  * frame #0: 0x000000010122ee88 Electron Framework`::GuestCurrentlyAudibleCallback() + 8 at browser_plugin_embedder.cc:200 [opt]
    frame #1: 0x00000001033de9c1 Electron Framework`::ForEachGuest() [inlined] Run + 161 at callback.h:129 [opt]
    frame #2: 0x00000001033de96c Electron Framework`::ForEachGuest() + 76 at web_view_manager.cc:69 [opt]
    frame #3: 0x000000010122ef36 Electron Framework`::AreAnyGuestsCurrentlyAudible() + 166 at browser_plugin_embedder.cc:207 [opt]
    frame #4: 0x00000001017cf5ec Electron Framework`::OnAudioStateChanged() + 60 at web_contents_impl.cc:1587 [opt]
    frame #5: 0x000000010153751a Electron Framework`::UpdateStreams() + 426 at audio_stream_monitor.cc:195 [opt]
    frame #6: 0x0000000101537de3 Electron Framework`::UpdateStreamAudibleStateOnUIThread() + 323 at audio_stream_monitor.cc:157 [opt]
    frame #7: 0x00000001034a4a56 Electron Framework`::RunTask() [inlined] Run + 23 at callback.h:99 [opt]
    frame #8: 0x00000001034a4a3f Electron Framework`::RunTask() + 335 at task_annotator.cc:101 [opt]
    frame #9: 0x00000001034dd76f Electron Framework`::RunTask() + 639 at message_loop.cc:421 [opt]
    frame #10: 0x00000001034dddca Electron Framework`::DoWork() [inlined] DeferOrRunPendingTask + 474 at message_loop.cc:432 [opt]
    frame #11: 0x00000001034dddbe Electron Framework`::DoWork() + 462 at message_loop.cc:480 [opt]
    frame #12: 0x0000000103609cca Electron Framework`::RunWork() + 42 at message_pump_mac.mm:455 [opt]
    frame #13: 0x000000010360ec8a Electron Framework`base::mac::CallWithEHFrame(void () block_pointer) + 10 at call_with_eh_frame_asm.S:36

@zcbenz zcbenz force-pushed the destroy-webcontents-sync branch 3 times, most recently from d5b5a65 to 2ed1a11 Compare November 2, 2018 11:03
@zcbenz
Copy link
Member Author

zcbenz commented Nov 2, 2018

The crash turned out to be a mistake when refactoring.

All tests are passing now.

@MarshallOfSound
Copy link
Member

@zcbenz The 4.0 backport failed, trop failed to report it because of a GitHub API error. Will work on a fix for trop for that but just a heads up for now 👍

MarshallOfSound added a commit to electron/trop that referenced this pull request Nov 2, 2018
Normally this means we send invalid annotations, so let's just send a
failure without them.

E.g. electron/electron#15541
Copy link
Member

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

app.on('ready', function () {
new BrowserView({}) // eslint-disable-line

process.nextTick(() => app.quit())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this has to be on the next tick ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to emulate the original crash case, having process.nextTick or not does not really affect the test.

MarshallOfSound added a commit to electron/trop that referenced this pull request Nov 3, 2018
#64)

Normally this means we send invalid annotations, so let's just send a
failure without them.

E.g. electron/electron#15541
@deepak1556
Copy link
Member

@zcbenz just remembered, we had disabled a spec in 69 due to the same crash https://github.com/orgs/electron/projects/24#card-13687849, can you try enabling it in this PR ? Thanks!

@zcbenz
Copy link
Member Author

zcbenz commented Nov 8, 2018

@zcbenz just remembered, we had disabled a spec in 69 due to the same crash https://github.com/orgs/electron/projects/24#card-13687849, can you try enabling it in this PR ?

The test is timeout on my machine, after quitting the app directly I'm seeing the client_map_.empty() assertion. I'll look into it in another PR.

Copy link
Member

@felixrieseberg felixrieseberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me and looks good. 👏 for the documentation in code, explains what's going on well!

@codebytere codebytere merged commit 746beb0 into master Nov 8, 2018
@release-clerk
Copy link

release-clerk bot commented Nov 8, 2018

Release Notes Persisted

Fix crash on exit when using BrowserView.

@codebytere codebytere deleted the destroy-webcontents-sync branch November 8, 2018 15:57
@miniak
Copy link
Contributor

miniak commented Mar 15, 2019

/trop run backport-to 3-1-x

@trop
Copy link
Contributor

trop bot commented Mar 15, 2019

The backport process for this PR has been manually initiated,
sending your 1's and 0's to "3-1-x" here we go! :D

@trop
Copy link
Contributor

trop bot commented Mar 15, 2019

I was unable to backport this PR to "3-1-x" cleanly;
you will need to perform this backport manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4.0 crashes on shutdown when using BrowserView
6 participants