Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Error thrown in xhr.onreadystatechange when javascript execution is suspended/resumed on iOS #6582

Closed
wants to merge 1 commit into from

Conversation

peleteiro
Copy link

Request Type: bug

How to reproduce: On iOS, javascript execution is suspended when user switches to another tab in browser, closes browser, performs back/forward using swipe gestions.
In our application, if http request is occurred when javascript execution is suspended/resumed, sometimes (apprx one time per dozen tries) the following error is thrown:

TypeError: 'null' is not an object (evaluating 'xhr.readyState')

src/ng/httpBackend.js
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) { // Error is thrown in this line
Debugging showed that xhr.onreadystatechange was invoked several times with readyState=4. On the first invocation xhr was nullified in completeRequest function, and then, on subsequent invocations, error was thrown.

Unfortunately, I could not reproduce the problem in small example. But I found that jQuery and Zepto have appropriate guards. Please see, for example, madrobby/zepto#633

Component(s): $http

Impact: large

Complexity: small

This issue is related to:

Detailed Description:

In certain cases Webkit will call the onreadystatechange method of a single XMLHttpRequest object multiple times indicating that it is ready (readyState == 4).

Other Comments:

The actual approach didn't work. I took the Zepto.js approach (see: madrobby/zepto#633).

In addition to manual and unit tests, I run a angular website with 250k unique visitor a day, I tested this patch there using getsentry.com and got no erros.

See: #5426

@mary-poppins
Copy link

Thanks for the PR! Please check the items below to help us merge this faster. See the contributing docs for more information.

  • Uses the issue template (#6582)

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@btford btford added the gh: PR label Mar 7, 2014
@mary-poppins
Copy link

I'm sorry, but I wasn't able to verify your Contributor License Agreement (CLA) signature. CLA signature is required for any code contributions to AngularJS.

Please sign our CLA and ensure that the CLA signature email address and the email address in this PR's commits match.

If you signed the CLA as a corporation, please let us know the company's name.

Thanks a bunch!

PS: If you signed the CLA in the past then most likely the email addresses don't match. Please sign the CLA again or update the email address in the commit of this PR.
PS2: If you are a Googler, please sign the CLA as well to simplify the CLA verification process.

@peleteiro peleteiro added cla: no and removed cla: yes labels Mar 7, 2014
@peleteiro
Copy link
Author

Sorry. It's done.

@mary-poppins
Copy link

CLA signature verified! Thank you!

Someone from the team will now triage your PR and it will be processed based on the determined priority (doc updates and fixes with tests are prioritized over other changes).

@pkozlowski-opensource
Copy link
Member

@peleteiro could you please confirm that it still happens with 1.3.x? The reason I'm asking is that the onreadystatechange handler is gone: https://github.com/angular/angular.js/blob/master/src/ng/httpBackend.js

@realityking
Copy link
Contributor

@pkozlowski-opensource This was fixed a while ago in 1.2 by confirming that xhr was still set (and unsettling it when the request was completed)

In 1.3 it shouldn't occur, when I removed the onreadystatechange handler I've tested that on load is only called once using the iOS 7 simulator.

I believe this can be closed.

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

Successfully merging this pull request may close these issues.

7 participants