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

AjaxObservable: complete subscribers on abort #4105

Closed
wants to merge 1 commit into from

Conversation

OliverJAsh
Copy link
Contributor

@OliverJAsh OliverJAsh commented Sep 6, 2018

Description:
It is possible for an XHR to be aborted externally, for example when the machine loses connectivity.

Currently, when the XHR is aborted in this way, the subscription remains.

In this case, I think we would want to complete the observable? Although it might also be useful to emit something to indicate it was aborted.

@cartant
Copy link
Collaborator

cartant commented Sep 6, 2018

Are you sure that the onabort event fires for anything other than an abort call? My reading of the whatwg spec is that the aborted flag can only be set via a call to the abort method.

@OliverJAsh
Copy link
Contributor Author

I tested it and the event was called when abort occurred due to sleeping my computer.

@cartant
Copy link
Collaborator

cartant commented Sep 6, 2018

I'm wondering if the behaviour differs between browsers and also if it differs depending on whether a connection is severed or cannot be established in the first place.

In any case, if onabort is to be wired up, I think it should see the observable error, rather than complete.

That's my two cents. I'll be interested to hear what others think about this.

@kwonoj
Copy link
Member

kwonoj commented Sep 7, 2018

Interesting. it doesn't look like ng/http handles onAbort as well: https://github.com/angular/angular/blob/master/packages/common/http/src/xhr.ts so far I give a quick peek.

What other libs does? if it's promise based, does it reject / or not handling, etcs? My immediate feeling is also this maybe error cases.

@OliverJAsh
Copy link
Contributor Author

if it's promise based, does it reject / or not handling, etcs?

I just attempted the same thing with fetch.

http://output.jsbin.com/kelayinizo/quiet makes a request that takes 10 seconds to complete.

If I sleep my computer in that time, here is what I find when I return:

Uncaught (in promise) TypeError: Failed to fetch

@benlesh
Copy link
Member

benlesh commented Sep 10, 2018

I would think the error event should fire on the XHR with readyState 0. Is that not the case?

xhr.onabort = () => {
const { subscriber, progressSubscriber } = (<any>xhrLoad);
if (progressSubscriber) {
progressSubscriber.complete();
Copy link
Member

Choose a reason for hiding this comment

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

complete is a signal of successful completion. This isn't correct. If it's aborted, it did not complete successfully.

@benlesh
Copy link
Member

benlesh commented Sep 10, 2018

I can't approve this one, because I don't think it's the right approach.

@OliverJAsh
Copy link
Contributor Author

Thanks for the review @benlesh, I agree it should emit error instead of complete, like fetch does.

I would think the error event should fire on the XHR with readyState 0. Is that not the case?

In my testing, the observable does not emit anything, so I guess no.

I'll update this PR to emit an error when the abort event is received?

@benlesh benlesh closed this Oct 9, 2018
@OliverJAsh
Copy link
Contributor Author

@benlesh This is still a bug. Could you reply to my previous comment? I'm happy to contribute

@OliverJAsh
Copy link
Contributor Author

Moved to #4251

@lock lock bot locked as resolved and limited conversation to collaborators Nov 11, 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.

4 participants