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

incorrect behavior of cache() #1628

Closed
unao opened this issue Apr 15, 2016 · 4 comments · Fixed by #1765
Closed

incorrect behavior of cache() #1628

unao opened this issue Apr 15, 2016 · 4 comments · Fixed by #1765
Assignees
Labels
bug Confirmed bug
Milestone

Comments

@unao
Copy link

unao commented Apr 15, 2016

RxJS version: 5.0.0-beta.6

Code to reproduce:

Rx.Observable
  .fromPromise(new Promise((res) => res(true)))
  .map(() => 'abc')
  .do(() => console.log('LOG_1'))
  .cache()
  .do(() => console.log('LOG_2'))
  .flatMap(() => Rx.Observable.timer(500)
    .flatMap(() => Rx.Observable.throw('ERR')))
  .retry(3)
  .subscribe(() => {})

Expected behavior: LOG_1 should happen once and LOG_2 four times:

LOG_1
LOG_2
LOG_2
LOG_2
LOG_2

Similarly to:

Rx.Observable.timer(1000)
  .map(() => 'abc')
  .do(() => console.log('LOG_1'))
  .cache()
  .do(() => console.log('LOG_2'))
  .flatMap(() => Rx.Observable.timer(500)
    .flatMap(() => Rx.Observable.throw('ERR')))
  .retry(3)
  .subscribe(() => {})

Actual behavior: LOG_1 appears four times, moreover after retry the order of logs is reversed.

LOG_1
LOG_2
LOG_2
LOG_1
Uncaught ObjectUnsubscribedError
LOG_2
LOG_1
Uncaught ObjectUnsubscribedError
LOG_2
LOG_1
Uncaught ObjectUnsubscribedError

Additional information: Both code snippets generate: Uncaught ObjectUnsubscribedError after each retry. demo

@unao
Copy link
Author

unao commented Apr 18, 2016

By any chance did anyone take a look at it? Is it a bug or am I doing something wrong?

@benlesh
Copy link
Member

benlesh commented Apr 18, 2016

I'll look into this very soon.

@benlesh benlesh self-assigned this Apr 18, 2016
@benlesh benlesh added the bug Confirmed bug label Apr 18, 2016
@unao
Copy link
Author

unao commented Apr 20, 2016

Just wonder if it may be somehow connected to: #1466.

@benlesh benlesh modified the milestone: 5.0.0 release Apr 29, 2016
benlesh added a commit that referenced this issue Jun 14, 2016
This is an initial pass at fixing the cache operator. There is still a lot to do. Ideally, the cache operator would use the lift mechanism. Also this is not well optimized as it is introducing a lot of closures. But it works, and that's the point for now.

fixes #1628
@lock
Copy link

lock bot commented Jun 7, 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 7, 2018
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

Successfully merging a pull request may close this issue.

2 participants