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 NPE caused by race condition when AMP page state changes before amp-analytics finishes initialization #18400

Merged
merged 2 commits into from Sep 27, 2018

Conversation

lannka
Copy link
Contributor

@lannka lannka commented Sep 26, 2018

Fixes #18395

@lannka lannka changed the title Fix NPE caused by race condition when AMP page state changes before a… Fix NPE caused by race condition when AMP page state changes before amp-analytics finishes initialization Sep 26, 2018
Copy link
Member

@calebcordry calebcordry left a comment

Choose a reason for hiding this comment

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

Should we have a test for this?

@@ -178,8 +182,13 @@ export class AmpAnalytics extends AMP.BaseElement {
return false;
}

// Page was unloaded - free up owned resources.
this.transport_.deleteIframeTransport();
if (this.iniPromise_) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmmm, I feel we should stop initiating iframeTransport once unlaid out, instead of wait for the promise to resolve and delete the iframe again.
I am ok to have this as a temporary solution but longterm this should be considered together with #18231

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This can be tricky to implement, as promise cannot be canceled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

even if we could cancel a promise, to support the following lifecycle:

active -> inactive : unlayoutCallback
inactive -> active : resumeCallback

we have to initialize everything in resumeCallback as well.

@lannka
Copy link
Contributor Author

lannka commented Sep 26, 2018

Test added

@lannka lannka merged commit 0d3b2be into ampproject:master Sep 27, 2018
@lannka lannka deleted the fix-null-transport branch September 27, 2018 00:33
calebcordry pushed a commit that referenced this pull request Sep 27, 2018
…mp-analytics finishes initialization (#18400)

* Fix NPE caused by race condition when AMP page state changes before amp-analytics finishes initialization

* add tests
torch2424 pushed a commit to torch2424/amphtml that referenced this pull request Oct 10, 2018
…mp-analytics finishes initialization (ampproject#18400)

* Fix NPE caused by race condition when AMP page state changes before amp-analytics finishes initialization

* add tests
Enriqe pushed a commit to Enriqe/amphtml that referenced this pull request Nov 28, 2018
…mp-analytics finishes initialization (ampproject#18400)

* Fix NPE caused by race condition when AMP page state changes before amp-analytics finishes initialization

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

Successfully merging this pull request may close these issues.

None yet

4 participants