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: send ELECTRON_BROWSER_CONTEXT_RELEASE asynchronously #20632

Merged
merged 2 commits into from
Oct 23, 2019

Conversation

miniak
Copy link
Contributor

@miniak miniak commented Oct 18, 2019

Description of Change

Fixes parts of #20086 by sending ELECTRON_BROWSER_CONTEXT_RELEASE asynchronously.
The synchronous send was added in #9389, which was necessary back then as we didn't have a unique identifier for each JS context.

Fixing ipcRenderer.sendSync() to not hang when the mojo connection is lost is also important, but more complicated.

Checklist

Release Notes

Notes: Fixed hang when closing a scriptable popup window using the remote module.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Oct 18, 2019
@miniak miniak self-assigned this Oct 18, 2019
@miniak miniak requested review from alexeykuzmin, zcbenz and nornagon and removed request for alexeykuzmin October 18, 2019 13:17
@miniak miniak marked this pull request as ready for review October 18, 2019 17:04
Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

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

works for me!

@nornagon
Copy link
Member

cc @loc

Copy link
Contributor

@loc loc left a comment

Choose a reason for hiding this comment

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

lgtm!

Copy link
Member

@MarshallOfSound MarshallOfSound left a comment

Choose a reason for hiding this comment

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

Blocking while I go back to my remote repro cases and check this, I believe the synchronous nature is required for race condition handling

@MarshallOfSound
Copy link
Member

Also this doesn't fix the root cause of #20086 it just hides the underlying issue

@zcbenz
Copy link
Member

zcbenz commented Oct 19, 2019

To add some background here:

The ELECTRON_BROWSER_CONTEXT_RELEASE message used to be required to be sent synchronously, so the remote references for current WebContents can be cleared before loading the new page, otherwise race conditions would happen.

However later there was some changes in Chromium that, the new page is pre-loaded before the old page gets destroyed, so race condition would happen even though the message was sent synchronously.

The race condition was then fixed by passing the ID of current context with the ELECTRON_BROWSER_CONTEXT_RELEASE message (#13603), so the remote references are cleared per-context instead of per-WebContents, and the sequence of messages does not matter anymore since then.

So technically the ELECTRON_BROWSER_CONTEXT_RELEASE message no longer has to be sent synchronously. However we have to ensure that the message has actually been sent when navigation happens, and I think we should add a test for it.

Also some note on how remote references are cleared:

Currently we have 2 ways of clearing remote references: one is listening to render-view-deleted event, and the other is sending the ELECTRON_BROWSER_CONTEXT_RELEASE message.

Both ways are required because render-view-deleted does not work for certain page navigations (depending on which Chromium version), and the ELECTRON_BROWSER_CONTEXT_RELEASE message can not be sent successfully when page is destroyed directly.

@zcbenz
Copy link
Member

zcbenz commented Oct 19, 2019

For the original issue #20086, before IPC module got migrated to mojo, the sendSync would simply fail when the page is being destroyed; but with mojo the sendSync is waiting for signal manually and Chromium would not unlock it for us automatically, resulting in hang when page is being destroyed.

@zcbenz zcbenz force-pushed the miburda/async-context-release branch from 7111346 to c71763d Compare October 19, 2019 01:15
@zcbenz
Copy link
Member

zcbenz commented Oct 19, 2019

I have added tests to ensure the remote references can be cleared for all cases (on navigation and on destroy()).

There is still problem that sendSync would hang when used in exit event while page is being destroyed directly, but I think it should be a separate problem.

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Oct 19, 2019
@lkonstantinov
Copy link

I have to agree with @MarshallOfSound - this is just fixing piecemeal and sweeping under the carpet the underlying issue. After we've patched this particular sendSync (about a month or so ago - see #20350) we've been hitting slew of IPC deadlock issues in other situations.

@miniak
Copy link
Contributor Author

miniak commented Oct 21, 2019

@lkonstantinov This PR is not pretending to be fixing the root cause, it's fixing #20086. The change to use an async IPC could have been made sooner as a refactoring as it does not have to be sync anymore as @zcbenz explained.

@zcbenz
Copy link
Member

zcbenz commented Oct 23, 2019

@MarshallOfSound Can you take another look of this?

Copy link
Member

@MarshallOfSound MarshallOfSound left a comment

Choose a reason for hiding this comment

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

All the old repro cases are fine with this change, thinking it through it should be OK. I don't want this PR to close the referenced issue though. All this does is minimize, it doesn't fix it.

@zcbenz
Copy link
Member

zcbenz commented Oct 23, 2019

I'm merging this and keeping the original issue open.

@zcbenz zcbenz merged commit ba8f802 into master Oct 23, 2019
@release-clerk
Copy link

release-clerk bot commented Oct 23, 2019

Release Notes Persisted

Fixed hang when closing a scriptable popup window using the remote module.

@zcbenz zcbenz deleted the miburda/async-context-release branch October 23, 2019 04:44
@trop
Copy link
Contributor

trop bot commented Oct 23, 2019

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

@trop trop bot removed the target/6-1-x label Oct 23, 2019
@trop
Copy link
Contributor

trop bot commented Oct 23, 2019

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

@trop
Copy link
Contributor

trop bot commented Oct 23, 2019

@miniak has manually backported this PR to "7-0-x", please check out #20715

@trop
Copy link
Contributor

trop bot commented Oct 23, 2019

@miniak has manually backported this PR to "6-1-x", please check out #20716

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
6.1.x
Fixed in 6.1.3
7.2.x
Fixed in 7.0.1
Development

Successfully merging this pull request may close these issues.

None yet

6 participants