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

AC3: Memory leak in mutation retains context object in memory on mutation failure #7160

Closed
kamilkisiela opened this issue Oct 14, 2020 · 3 comments

Comments

@kamilkisiela
Copy link
Contributor

kamilkisiela commented Oct 14, 2020

Intended outcome:
Object passed as context to mutate method should be released when Promise is settled, instead of being retrained in memory.

The MutationStore holds a reference to an Error forever, it never gets deleted and it's never accessed anywhere in Apollo Client, just in Dev Tools. So I think, if connectToDevTools are disabled (or NODE_ENV === 'production' or typeof window === 'undefined) then storing an Error in MutationStore` no longer makes sense.

Actual outcome:
context object is retained in memory by AC3.

How to reproduce the issue:
Use mutate with context set. Apollo keeps reference to that object even when mutation is done, and promise is settled (and all references has been destructed).

You can find a complete reproduction (as a Jest test) here:
https://github.com/dotansimha/apollo-very-pessimism/tree/mutation

Instruction:

yarn --force
yarn test

I also used patch-package that represents my PR with a fix, to enable it, please modify package.json

  "scripts": {
-    "disabled:postinstall": "patch-package",
+    "postinstall": "patch-package",

And run

yarn --force
yarn test

Versions


  System:
    OS: macOS 10.15.7
  Binaries:
    Node: 10.18.0 - ~/.nvm/versions/node/v10.18.0/bin/node
    Yarn: 1.22.4 - ~/.yarn/bin/yarn
    npm: 6.13.4 - ~/.nvm/versions/node/v10.18.0/bin/npm
  Browsers:
    Chrome: 86.0.4240.75
    Edge: 86.0.622.38
    Firefox: 79.0
    Safari: 14.0
  npmPackages:
    @apollo/client: 3.2.4 => 3.2.4 

@kamilkisiela
Copy link
Contributor Author

Continuation of #7149 (comment)

@benjamn
Copy link
Member

benjamn commented Oct 16, 2020

@kamilkisiela These changes have been published in @apollo/client@3.3.0-beta.13, fyi.

@benjamn benjamn added this to the Post 3.0 milestone Oct 16, 2020
@hwillson
Copy link
Member

Fixed in @apollo/client@3.3.0 - thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants