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(ajax): Only set timeout & responseType if request is asynchronous #2486

Merged
merged 2 commits into from
Jun 14, 2017

Conversation

jkrehm
Copy link
Contributor

@jkrehm jkrehm commented Mar 23, 2017

Description:

Setting async: false in the call to Observable.ajax results in an error:

DOMException: Failed to set the 'timeout' property on 'XMLHttpRequest': Timeouts cannot be set for synchronous requests made from a document.

You can observe the behavior here: https://jsfiddle.net/jkrehm/k4o9do0q/1/

My solution is simply to wrap the code that sets timeout and responseType (also a problem) in an if-statement so they're only set if async: true (the default).

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0003%) to 97.689% when pulling 7d5e752 on hp-mobile:fix-sync-ajax into 01e1343 on ReactiveX:master.

@chrisnoringovo
Copy link

chrisnoringovo commented Mar 24, 2017

LGTM, missing an update in a test though shouldnt there be a spec/observables/dom/ajax-spec.ts that needs this case added and asserted?

@jkrehm
Copy link
Contributor Author

jkrehm commented Mar 24, 2017

As far as I can tell, the current tests in spec/observables/dom/ajax-spec.ts do not hit this code. They use MockXMLHttpRequest that has its own send function. I spent an hour trying to make the test work before dropping both console.log and throw statements into src/observable/dom/AjaxObservable.ts's send function and ran the tests and neither the log nor exception showed up.

Am I missing something obvious?

Edit: I'm an idiot and didn't rebuild the project code after adding my console.log and throw. Simply building the tests doesn't take care of that. I'll continue trying to debug the test for a bit.

@chrisnoringovo
Copy link

look, I'm not deciding anything here, at all. If it was me maintaining something as big as Rxjs I would want to have a test that proves a bug exist. A fix made and a test that shows the bug no longer exist. If it is possible. If really hard to test then maybe some example runs showing the bug seems resolved. For example used to be : "some code" is now : "some code". So if its hard or impossible to test I would just amend the description with a code snippet where it works.. You already added a jsFiddle which is good

@coveralls
Copy link

Coverage Status

Coverage increased (+0.0003%) to 97.689% when pulling 1e73755 on hp-mobile:fix-sync-ajax into 01e1343 on ReactiveX:master.

@jkrehm
Copy link
Contributor Author

jkrehm commented Mar 24, 2017

Added two tests: one for asynchronous, one for synchronous. It required changing the MockXMLHttpRequest a bit to (a) include async as a property and (b) not require that responseType be set (since synchronous calls cannot set that).

Hopefully that provides enough coverage for this issue. It doesn't show a good before/after shot of it working vs not working (the jsFiddle will have to suffice for the "not working" part) but hopefully it helps prevent future regressions.

@jkrehm
Copy link
Contributor Author

jkrehm commented Apr 6, 2017

Anything I can do to help this issue get merged? A project I'm working on requires sync requests in one scenario (iOS Safari) and we cannot use it there because of this issue. I'm happy to help however I can to make sure it's included in a future release.

@regou
Copy link

regou commented Jun 2, 2017

At what state about this issue? Can we merge jkrehm's pr?
I understand the Sync XHR is deprecated, but as long as rxjs support it, the code should be done right

@benlesh benlesh merged commit 380fbcf into ReactiveX:master Jun 14, 2017
@benlesh
Copy link
Member

benlesh commented Jun 14, 2017

Thanks @jkrehm

@jkrehm jkrehm deleted the fix-sync-ajax branch June 14, 2017 20:08
@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants