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

fix(observeOn): release action references on teardown #6559

Merged
merged 4 commits into from Aug 13, 2021

Conversation

kwonoj
Copy link
Member

@kwonoj kwonoj commented Aug 12, 2021

Description:

Looks like we regressed #2244 while refactoring.

This PR brings up theoritically same changes to old fixes to release references once action is dispatched.

I have verified manually via devtools, but not sure if there's good way to create test case for this. Previous test case was inspecting deep internals.

BREAKING CHANGE:

Related issue (if exists):

@kwonoj kwonoj requested a review from benlesh August 12, 2021 16:50
@kwonoj kwonoj changed the title observeOn teardown actions fix(observeOn): release action references on teardown Aug 12, 2021
@benlesh
Copy link
Member

benlesh commented Aug 12, 2021

@kwonoj I think the bug is somewhere else. The Action returned by the schedule call extends Subscription. Therefor, when the Action unsubscribe is called, it should remove itself from whatever Subscription it has been added to.

However, what I'm not seeing is where the Action should unsubscribe itself after it has successfully executed, and not rescheduled. 🤔

I'm going to take a look at this. But I think maybe this isn't the right solution.

Regardless, I'm really not a fan of our Scheduler architecture, and I'm going to be trying to think of ways to migrate us to something better soon.

@kwonoj
Copy link
Member Author

kwonoj commented Aug 12, 2021

However, what I'm not seeing is where the Action should unsubscribe itself after it has successfully executed, and not rescheduled

I think that's crux of this issue? afaik we don't have places action self-unsubscribes once it complets. This is essentially we did before, and refactoring removed it.

I'm going to take a look at this.

Fine for me.

Regardless, I'm really not a fan of our Scheduler architecture,

I think most of us are on the same page, for me mostly where we have schedulers & schedules actions.

@kwonoj
Copy link
Member Author

kwonoj commented Aug 12, 2021

@benlesh
Copy link
Member

benlesh commented Aug 12, 2021

@kwonoj Okay, so digging into this.... There's some clean up I can do to the code but the reason we keep around the Actions is because of the design of rescheduling. Technically, you can reschedule an action Asynchronously because of closures therefor, we can't unsubscribe the Action and have it remove itself from any parent subscription simply because it executed.

Ultimately, I now believe that this form of rescheduling is a design flaw that necessitates memory leaks or extra clean up code that requires "deep knowledge" of RxJS internals. Honestly, the requirement of "deep knowledge" of scheduler behaviors is one of the reasons I strongly believe using schedulers, in general, is inadvisable.

I think long-term we need to move away from our current Scheduler architecture, and move towards something more simplified. In the short term, we can fix observeOn in a manner similar to what we're doing here, but any user-land implementations leveraging our Schedulers will have the same problems with no obvious solutions.

@kwonoj
Copy link
Member Author

kwonoj commented Aug 12, 2021

@benlesh

because of the design of rescheduling

Yup, that's pretty much what I shared in slack channel.

the requirement of "deep knowledge" of scheduler behaviors is one of the reasons I strongly believe using schedulers, in general, is inadvisable.

agreed.

I think long-term we need to move away from our current Scheduler architecture, and move towards something more simplified

agreed again.

but any user-land implementations leveraging our Schedulers will have the same problems with no obvious solutions

it is already happening anyway, isn't it? as long as someone uses scheduling, or even plain observeOn operator, they're hitting this.

In the short term

I agree with all of this including long term fix. For now, I'd like to suggest short term fix to resurrect what we did previously, or similar way - while techinically it is not desirable, it is not breaking changes for the observeOn operator itself at least, and this impacts userland like redux-observable directly. (for now, any user uses redux-observable hits this 100%).

@kwonoj
Copy link
Member Author

kwonoj commented Aug 12, 2021

Just clarifying, I'm not saying this PR as-is should be checked in. I'm fine with other short term solutions.

@@ -146,6 +146,8 @@
"@types/sinon": "4.1.3",
"@types/sinon-chai": "2.7.29",
"@types/source-map": "^0.5.2",
"@typescript-eslint/eslint-plugin": "^4.29.1",
"@typescript-eslint/parser": "^4.29.1",
Copy link
Member

Choose a reason for hiding this comment

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

I feel like these are welcome changes... but are they necessary in this PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can spliot actually, it was due to I got annoyed editor actually failed to initiate eslint. Up to you - but this should be harmless for the fix itself & other editor experiences.

return operate((source, subscriber) => {
/**
Copy link
Member

Choose a reason for hiding this comment

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

@kwonoj please review, I've changed the approach just a little bit, and I've added detailed comments.

Copy link
Member Author

Choose a reason for hiding this comment

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

🚢

@benlesh
Copy link
Member

benlesh commented Aug 13, 2021

Citing @kwonoj's 🚢 here: #6559 (comment) in lieu of an approval, I'll take it.

@benlesh benlesh merged commit 5d0e41e into master Aug 13, 2021
@kwonoj kwonoj deleted the observeOn-teardown-actions branch August 13, 2021 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants