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 when resubscribed #5233

Closed
aquark opened this issue Jan 15, 2020 · 2 comments
Closed

fromFetch throws AbortError when resubscribed #5233

aquark opened this issue Jan 15, 2020 · 2 comments
Labels
bug Confirmed bug

Comments

@aquark
Copy link

aquark commented Jan 15, 2020

Bug Report

Current Behavior
When an Observable created with fromFetch is unsubscribed and then resubscribed, it immediately throws AbortError.

Reproduction

const o$ = fromFetch(url, {})
o$.subscribe()
o$.unsubscribe()
o$.subscribe()

Expected behavior
Each subscription to the observable should be independent. Looking at the code, the problem is that the init object from the function parameters is reassigned within the observable. Since this variable is from the closure it is shared across subscriptions, so subsequent subscriptions use the same abort signal which was already aborted and therefore always abort immediately.

Environment

  • Runtime: Node 12
  • RxJS version: 6.5.4

Possible Solution
Instead of reassigning to the function parameters, assign to a local variable within the Observable.

As a workaround, always wrapping the fromFetch in defer should work.

@cartant
Copy link
Collaborator

cartant commented Jan 15, 2020

It's possible that this was fixed in master - in #5110 - but not backported to version 6.

@cartant
Copy link
Collaborator

cartant commented Jan 15, 2020

Yeah. You are right. It needs to assigned to a variable that's declared within new Observable. It should not be assigned to the parameter.

@cartant cartant added the bug Confirmed bug label Jan 15, 2020
cartant added a commit to cartant/rxjs that referenced this issue Jan 15, 2020
cartant added a commit to cartant/rxjs that referenced this issue Jan 15, 2020
benlesh pushed a commit that referenced this issue Jan 20, 2020
* test: add failing test for #5233

* fix: don't reassign closed-over parameter in fromFetch

Closes #5233

* chore: add type annotation for variable
martinsik pushed a commit to martinsik/rxjs that referenced this issue Feb 15, 2020
* test: add failing test for ReactiveX#5233

* fix: don't reassign closed-over parameter in fromFetch

Closes ReactiveX#5233

* chore: add type annotation for variable
@lock lock bot locked as resolved and limited conversation to collaborators Feb 21, 2020
cpojer pushed a commit to react-native-community/rxjs that referenced this issue Mar 20, 2020
* test: add failing test for ReactiveX#5233

* fix: don't reassign closed-over parameter in fromFetch

Closes ReactiveX#5233

* chore: add type annotation for variable
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

2 participants