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(chromium): fix a race in persistent context launch #1702

Merged
merged 1 commit into from Apr 8, 2020
Merged

fix(chromium): fix a race in persistent context launch #1702

merged 1 commit into from Apr 8, 2020

Conversation

dgozman
Copy link
Contributor

@dgozman dgozman commented Apr 8, 2020

We should stop attaching to existing targets immediately after Target.setAutoAttach response arrives, otherwise we have a window for double attach.

@@ -50,24 +50,35 @@ export class CRBrowser extends BrowserBase {
const connection = new CRConnection(SlowMoTransport.wrap(transport, slowMo));
const browser = new CRBrowser(connection);
const session = connection.rootSession;
const promises = [
session.send('Target.setDiscoverTargets', { discover: true }),
Copy link
Collaborator

Choose a reason for hiding this comment

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

where did this go?

Copy link
Member

Choose a reason for hiding this comment

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

We don't use it except for initial target discovery (before auto attach is on).

@@ -50,24 +50,35 @@ export class CRBrowser extends BrowserBase {
const connection = new CRConnection(SlowMoTransport.wrap(transport, slowMo));
const browser = new CRBrowser(connection);
const session = connection.rootSession;
const promises = [
session.send('Target.setDiscoverTargets', { discover: true }),
Copy link
Member

Choose a reason for hiding this comment

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

We don't use it except for initial target discovery (before auto attach is on).

// First page and background pages in the persistent context are created automatically
// and may be initialized before we enable auto-attach.
function attachToExistingPage({targetInfo}: Protocol.Target.targetCreatedPayload) {
if (targetInfo.type !== 'page' && targetInfo.type !== 'background_page')
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated to thus PR but this should also include service workers I believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I'll fix it right away.


const startDiscover = session.send('Target.setDiscoverTargets', { discover: true });
const autoAttachAndStopDiscover = session.send('Target.setAutoAttach', { autoAttach: true, waitForDebuggerOnStart: true, flatten: true }).then(() => {
// All targets collected before setAutoAttach response will not be auto-attached, the rest will be.
Copy link
Member

Choose a reason for hiding this comment

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

Can you help me understand how it can happen? Does it imply that between handling Target.setAutoAttach and Target.setDiscoverTargets (sent synchronously one after another ) the browser may create new targets?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we send them synchronously, but they arrive to the browser with arbitrary delay.

session.on('Target.targetCreated', attachToExistingPage);

const startDiscover = session.send('Target.setDiscoverTargets', { discover: true });
const autoAttachAndStopDiscover = session.send('Target.setAutoAttach', { autoAttach: true, waitForDebuggerOnStart: true, flatten: true }).then(() => {
Copy link
Member

Choose a reason for hiding this comment

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

we again have to rely on the fact that no other messages will be handled before the response promise :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, that's our contract as far as I understand.

Copy link
Member

@yury-s yury-s Apr 8, 2020

Choose a reason for hiding this comment

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

I'd say this is an implementation detail which I'd rather not rely upon if possible. But this is not the only place though so it's fine. Alternatively, we could attach to all discovered targets after disabling discovery mode but preliminary checking if we haven't attached to it yet.

We should stop attaching to existing targets immediately after
Target.setAutoAttach response arrives, otherwise we have a window
for double attach.
@dgozman dgozman merged commit 5b4d32d into microsoft:master Apr 8, 2020
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.

None yet

3 participants