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

fromFetch throws AbortError #4739

Closed
strout opened this issue Apr 26, 2019 · 4 comments
Closed

fromFetch throws AbortError #4739

strout opened this issue Apr 26, 2019 · 4 comments
Labels
bug Confirmed bug

Comments

@strout
Copy link

strout commented Apr 26, 2019

Bug Report

Current Behavior
fromFetch seems to fail with AbortError when I would expect it to succeed.

Reproduction

This code throws an AbortError:

fromFetch('https://jsonplaceholder.typicode.com/todos/1')
  .pipe(switchMap(resp => resp.json()))
  .subscribe(json => console.log(json));

Expected behavior
The snippit above should complete and log the response to the console.

Environment

  • Runtime: Chrome 74, Firefox 66
  • RxJS version: 6.5.1

Possible Solution
In the definition of fromFetch(), don't call controller.abort() if it has already emitted a value. Perhaps set a flag (reuse/rename the unsubscribed flag) before calling subscriber.next.

@cartant cartant added the bug Confirmed bug label Apr 26, 2019
cartant added a commit to cartant/rxjs that referenced this issue Apr 26, 2019
@benlesh benlesh closed this as completed in 1dc09e9 May 2, 2019
@felixfbecker
Copy link
Contributor

@cartant how does this happen? Shouldn't the AbortError be ignored if the Observable unsubscribed?

@cartant
Copy link
Collaborator

cartant commented May 10, 2019

It aborts the promise returned by resp.json(), IIRC. I think I put more info in the related PR.

@felixfbecker
Copy link
Contributor

So in that code sample provided in the issue description, why would that matter?

@cartant
Copy link
Collaborator

cartant commented May 10, 2019

Try the StackBlitz and you'll see. Sometimes it works and sometimes it fails. Bottom line is that abort should not be called upon the normal unsubscription that follows completion. See also #4744.

BioPhoton pushed a commit to BioPhoton/rxjs that referenced this issue May 15, 2019
* test(fetch): test expectations after complete

* fix(fromFetch): don't abort if fetch resolves

Closes ReactiveX#4739
@lock lock bot locked as resolved and limited conversation to collaborators Jun 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

3 participants