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

asyncIterator should not subscribe until first call to next() to prevent memory leaks #197

Closed
jedwards1211 opened this issue Dec 24, 2019 · 0 comments · Fixed by #198
Closed

Comments

@jedwards1211
Copy link
Contributor

jedwards1211 commented Dec 24, 2019

This is a dupe of #124, but everyone in that thread completely missed the root cause of the memory leak.

If using a for await loop, the return()/throw() methods of an AsyncIterator aren't going to get called unless iteration actually begins (by calling next()).

Because of this, calling subscribeAll in the PubSubAsyncIterator constructor is a memory leak. subscribeAll should instead be called in the first call to next(), because only then do you have a guarantee that consuming code is going to call return() or throw() to clean up the subscription.

graphql-subscriptions merged my PR to not subscribe until the first call to next() in their PubSubAsyncIterator implementation, so this is legit.

Here is a screenshot of our memory leaks in production related to this (you can see the PubSubAsyncIterator in the Retainers section):

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant