-
Notifications
You must be signed in to change notification settings - Fork 3k
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(shareReplay): handle possible memory leaks #5932
Conversation
I tested this locally, and the changes in this PR don't fix the memory leak reported on #5931, so I'm closing it for now. I will re-open it if I find a solution. |
Actually, sorry, it does fix the memory leak |
@josepot @benlesh That is, we have to ask why an instance of With that in mind, I have made this related PR, so that this kind of thing will (hopefully) never be a problem again for any operator (not just |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes don't at all affect the logic of what's going on in this operator, and wouldn't really effect the memory usage.
As I stated in the related issue, it seems the problem is confusion around the default behavior of shareReplay
. Which, IMO, has been an ongoing problem.
Hopefully the new operators in version 7 will gain more adoption and we can leave these confusing days behind us.
I'm going to close this PR because the changes don't really do anything (as I outlined above). If there's proof that this changes the memory usage, I'll be happy to take another look. |
I'm sorry if I'm being annoying, but @benlesh or @cartant could you please have a look at this codesandbox? 🙏. It's simply doing a Also, thanks a lot for the amazing work that you are doing on v7. I've been using it on a project of mine and so far things are looking great! There is just one little thing that's annoying me: which is that I'm seeing code in a chunk that I really think that it should have been "tree shaken" and it wasn't. I'm still investigating, I will open an issue or a discussion in the coming days to explain this better and I will make sure that when I open the issue I can give you as much info as I can. Thanks again! |
@josepot I'll have a look at this in a bit. I'll push a test to this branch to clear things up. |
Derp. @josepot is correct. I overlooked that synchronously, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Add a comment, as suggested, above the new conditional.
-
Add a test that proves this resolves the issue.
RELATED: we'll need to create a second PR that adds the same test to master
.
3e64f6b
to
aff9283
Compare
✔️
Is that possible without testing the internals? 🤔 I mean, the only way that I can think off, involves exposing an implementation detail... which IMO wouldn't be worth it. I'm very open to suggestions. EDIT: I found this tool, but I don't see it in the list of dev-dependencies... Maybe you are using a similar tool/approach in other tests? If that's the case, could you please point me in the right direction? 🙏 I'd love to learn how to properly test for memory leaks. Thanks! |
Yes. I'll add one soon. |
IDK what these build failures are. I hate CI so much. |
@cartant hats off to you for that test!! 👏 👏 👏 TIL about PS @voliva check this out we should start using this on |
86f6342
to
a3f8984
Compare
@josepot IDK whether or not you can see the details of the CI failure, but this is what's breaking:
🤷♂️ Maybe there is was a breaking change in the node types that match whatever semver is in this branch's |
Thanks a lot @cartant ! Yep, I can see that. There were 2 different checks failing, one has been fixed by my latest commit (a linting issue, aparently). And this one, I'm investigating... The first thing that I tried was rebasing the branch from 6.x, just in case, but that didn't help... And yeah, based on a quick google search that error normally indicates an issue with the node types. I will investigate a bit more later. Thanks again. |
Yep, I think that's the issue... Because -according to the logs- the task that fails is running under node@13.14.0: /usr/bin/tar xz --warning=no-unknown-keyword -C /home/runner/work/_temp/7bd7433d-ba81-4237-ac22-1ea42ffa579b -f /home/runner/work/_temp/1e3c4cf6-32b1-405a-90d3-3bb7230d395f
/opt/hostedtoolcache/node/13.14.0/x64/bin/node --version
v13.14.0 And the types that are defined on the
Thanks for the fix @cartant ! |
@@ -262,4 +262,26 @@ describe('shareReplay operator', () => { | |||
expectObservable(result).toBe(expected); | |||
}); | |||
|
|||
const FinalizationRegistry = (global as any).FinalizationRegistry; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a clever use of FinalizationRegistry
.
Description:
Fixes possible memory leaks caused by the
shareReplay
operatorRelated issue (if exists):
#5931