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

Make sure to clean context during tearDownQuery #7276

Merged
merged 2 commits into from
Nov 20, 2020

Conversation

dotansimha
Copy link
Contributor

@dotansimha dotansimha commented Nov 2, 2020

Hi @benjamn

This PR should ensure that even if ObservableInfo remains in memory, it won't hold a reference to user-object context after tear-down.

The background is a memory-leak we are chasing in a large-scale app. I think the existence of the context reference in Apollo just makes it harder to detect, since it retaining it with no reason.
I think even in a use-case of subscribe over a watchQuery observable, without unsubscribing reproduces that, since Apollo isn't removing the ObservableQuery while there are subscribers.

Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

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

@dotansimha Although I hope we can prevent torn-down ObservableQuery objects from remaining in memory unnecessarily, I agree this blunt approach seems like a worthwhile extra layer of defense.

@benjamn benjamn changed the base branch from main to release-3.3 November 20, 2020 21:04
@benjamn benjamn merged commit 3e58873 into apollographql:release-3.3 Nov 20, 2020
@francisu
Copy link

francisu commented Feb 9, 2021

@benjamn when an observable query is re-observed, it seems to come back to life (I don't know the exact details of this mechanism, but it's happening in my app). In this case however, the context has been deleted, so the query is incorrectly running without the originally specified context. I think this PR should be backed out. The context memory will be freed with the ObservableQuery is garbage collected.

benjamn added a commit that referenced this pull request Feb 12, 2021
Thanks to @francisu for pushing back on the reasoning behind #7276:
#7276 (comment)

Thanks to #7661, we now have a system for programmatically testing garbage
collection of discarded objects, so we can actually enforce the
expectation that the whole ObservableQuery is garbage collected after the
last subscriber is removed (which tears down the ObservableQuery and
removes it from the QueryManager).
@benjamn
Copy link
Member

benjamn commented Feb 12, 2021

@francisu Agreed! Fix incoming: #7695

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.

3 participants