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

[DO NOT MERGE][NEXT?] Unsubscribe source observable immediately after it completes or errors #2457

Closed
wants to merge 3 commits into from

Conversation

mpodlasin
Copy link
Contributor

Disclaimer:
For discussion. Either I am doing something very smart or something very dumb right now. ;)

Problem:
Currently many operators still subscribe for some time to source observables after they completed, and thus do not call teardown logic immediately after completion. These kind of marbles are in many tests:

---a-----b-----c-----|               <- source observable
^------------------------------!    <- subscription to that observable

It is a source of very subtle bugs, like: #2455

It also seems that this goes against tc39 proposal, which guarantees that source will be unsubscribed whenever it sends complete or error notification to an observer: https://tc39.github.io/proposal-observable/#subscription-observer-objects

There are operators that have to manually trigger their unsubscription to normalilze their behaviour: https://github.com/ReactiveX/rxjs/blob/master/src/operator/take.ts#L80

@kwonoj
Copy link
Member

kwonoj commented Mar 12, 2017

My personaly suggestion is starting for issue to discuss details first for these kind of cases, as it is not ceratin what desired behavior we want to have, this PR probably stall very long time and either be closed or required lot of updates in further.

@kwonoj
Copy link
Member

kwonoj commented Mar 12, 2017

(But not saying this should be closed now since it's already prepped)

@rxjs-bot
Copy link

rxjs-bot commented Mar 12, 2017

Warnings
⚠️ commit message does not follows conventional change log (1)

(1) : RxJS uses conventional change log to generate changelog automatically. It seems some of commit messages are not following those, please check contributing guideline and update commit messages.

Generated by 🚫 dangerJS

@coveralls
Copy link

Coverage Status

Coverage increased (+0.004%) to 97.692% when pulling 270f2ad on Podlas29:subscriber-fix into 69d051b on ReactiveX:master.

@mpodlasin
Copy link
Contributor Author

@kwonoj Will have that in mind, but I wanted to see if my planned fix will work and won't break stuff it shouldn't.

@mpodlasin mpodlasin changed the title [DO NOT MERGE][NEXT?] Do not subscribe to source observables after they completed or errored [DO NOT MERGE][NEXT?] Unsubscribe source observable immediately after it completes or errors Mar 12, 2017
@kwonoj
Copy link
Member

kwonoj commented Mar 12, 2017

@Podlas29 if you don't mind, would you create issue? It's better to make discussion continues on issue, not on PR.

@trxcllnt
Copy link
Member

@Podlas29 the spirit of the PR seems right, but allocating an extra Subscription per Subscriber shouldn't be necessary. We essentially hook up the "parent" subscription here, so I have a hunch we can update this PR to use that directly.

@mpodlasin
Copy link
Contributor Author

@kwonoj #2459

@mpodlasin
Copy link
Contributor Author

@trxcllnt Awesome pointer. Thanks! I was able to get rid of all unneccessary subscriptions.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 97.707% when pulling 1c5282a on Podlas29:subscriber-fix into 69d051b on ReactiveX:master.

1 similar comment
@coveralls
Copy link

coveralls commented Mar 13, 2017

Coverage Status

Coverage increased (+0.02%) to 97.707% when pulling 1c5282a on Podlas29:subscriber-fix into 69d051b on ReactiveX:master.

@benlesh
Copy link
Member

benlesh commented Mar 13, 2017

This PR will require a LOT of review. The behavior seems right-ish, on the surface, and the spirit of the PR seems solid. But there are a lot of questions and even more changes to review.

Most of our tests were modeled after the tests that existed in Rx4 and under. So many of these changes may incur breaking changes for the historical use of the library.

It also looks like (at a quick glance) that we're adding another Subscription reference per subscription, as well as a few new publicly available properties and methods.

Questions:

How does this affect performance?
How about memory pressure?
Who will this break?
Is this fixing a problem that many people are affected by? Is it really a problem?

There are just so many behavioral changes here, it's really going to be hard to tackle this and give it the proper attention it deserves in any reasonable amount of time.

@benlesh
Copy link
Member

benlesh commented Mar 13, 2017

As an aside: the format of your commit messages is incorrect.

Perhaps it would be better to file each bug you think is a bug separately with it's accompanying test from this PR, so each one could be discussed individually?

@mpodlasin
Copy link
Contributor Author

mpodlasin commented Mar 14, 2017

@benlesh - please take a look at #2459 In following days I will try to flesh out the problem more, provide more examples as well as alternative plans for fixing it in a more controlled/gradual way.

Also bear in mind I am 100% okay with closing this and fixing stuff on case-to-case basis. I just wanted to be sure that we are all aware of an issue. For me it's very fundamental weakness from conceptual standpoint, but I fully understand pragmatic approach.

@benlesh
Copy link
Member

benlesh commented May 4, 2018

Okay, I think this PR should be redone and added as a bug fix during 6.0. It's not really a "breaking" change to anything but a broken behavior, IMO.

@benlesh
Copy link
Member

benlesh commented Jul 27, 2018

Closing in favor of #3963, which is an attempt to pull this in.

@benlesh benlesh closed this Jul 27, 2018
cartant added a commit to cartant/rxjs that referenced this pull request Jul 28, 2018
benlesh added a commit that referenced this pull request Jul 29, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Aug 26, 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.

7 participants