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(graphql): prevent potential memory leak for mostly falsy filter function #2605

Merged

Conversation

niceandneat
Copy link

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

As apollographql/graphql-subscriptions#209 saids, a filter function that returns mostly false can cause loops in Promises. This leads to a memory leak.

Issue Number: N/A
Relevant Issue: apollographql/graphql-subscriptions#212

What is the new behavior?

Applied changes of above PR to existing function createAsyncIterator.
Now it does not stack up awaiting Promises.

Credit to. @urossmolnik

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Comment on lines 18 to 20
"test:e2e": "node --expose-gc ../../node_modules/.bin/jest --config ./tests/jest-e2e.ts --runInBand && yarn test:e2e:fed2",
"test:e2e:fed2": "node --expose-gc ../../node_modules/.bin/jest --config ./tests/jest-e2e-fed2.ts --runInBand",
"test:e2e:dev": "node --expose-gc ../../node_modules/.bin/jest --config ./tests/jest-e2e.ts --runInBand --watch"
Copy link
Member

Choose a reason for hiding this comment

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

Appreciate you wanting to show that there's not a memory leak, but is it really necessary to change the commands themselves rather than possibly updating the CI to watch for this?

Copy link
Author

Choose a reason for hiding this comment

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

I found a solution to use global.gc() without node flags. Check out the new PR.

@niceandneat niceandneat force-pushed the fix-memory-leak-async-iterator branch from aea0458 to cd29258 Compare February 6, 2023 04:47
@kamilmysliwiec kamilmysliwiec merged commit 6796299 into nestjs:master Feb 6, 2023
@kamilmysliwiec
Copy link
Member

lgtm

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

Successfully merging this pull request may close these issues.

3 participants