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

usage reporting: fix memory leak #6998

Merged
merged 1 commit into from Oct 7, 2022

Conversation

glasser
Copy link
Member

@glasser glasser commented Oct 7, 2022

A data structure in the usage reporting plugin would get a new entry each time the server's schema changed. Old entries would never be deleted, though their values would be shrunk to a minimum size.

It seems that this was not good enough and is producing notable memory leaks for some folks. So let's fix it!

The reason for the old behavior was to be really careful to never write to a report that may have already been taken out of the map and sent. Previously this was accomplished by having the main entry in the map never change. Now this is accomplished by making sure that we never write to the report any later than immediately (and synchronously) after we pull it out of the map.

Fixes #6983.

@netlify
Copy link

netlify bot commented Oct 7, 2022

Deploy Preview for apollo-server-docs ready!

Name Link
🔨 Latest commit 49c82aa
🔍 Latest deploy log https://app.netlify.com/sites/apollo-server-docs/deploys/63409d3ddad31000084c36a1
😎 Deploy Preview https://deploy-preview-6998--apollo-server-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 7, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 49c82aa:

Sandbox Source
Apollo Server Typescript Configuration
Apollo Server Configuration
Apollo Server Issue #6983

@glasser
Copy link
Member Author

glasser commented Oct 7, 2022

For the sake of efficiency I'm going to merge this today (I'd like to get this into the hands of the user who reported this to see if it fixes their issue) but I'd appreciate post-merge review from @trevor-scheer and ideally from @bonnici as well.

A data structure in the usage reporting plugin would get a new entry
each time the server's schema changed. Old entries would never be
deleted, though their values would be shrunk to a minimum size.

It seems that this was not good enough and is producing notable memory
leaks for some folks. So let's fix it!

The reason for the old behavior was to be really careful to never write
to a report that may have already been taken out of the map and sent.
Previously this was accomplished by having the main entry in the map
never change. Now this is accomplished by making sure that we never
write to the report any later than immediately (and synchronously) after
we pull it out of the map.

Fixes #6983.
@glasser glasser force-pushed the glasser/usage-reporting-memory-leak branch from af3c9bb to 49c82aa Compare October 7, 2022 21:42
@glasser glasser merged commit 233b44e into version-4 Oct 7, 2022
@glasser glasser deleted the glasser/usage-reporting-memory-leak branch October 7, 2022 21:52
@github-actions github-actions bot mentioned this pull request Oct 7, 2022
glasser added a commit that referenced this pull request Oct 7, 2022
A data structure in the usage reporting plugin would get a new entry
each time the server's schema changed. Old entries would never be
deleted, though their values would be shrunk to a minimum size.

It seems that this was not good enough and is producing notable memory
leaks for some folks. So let's fix it!

The reason for the old behavior was to be really careful to never write
to a report that may have already been taken out of the map and sent.
Previously this was accomplished by having the main entry in the map
never change. Now this is accomplished by making sure that we never
write to the report any later than immediately (and synchronously) after
we pull it out of the map.

Fixes #6983. Backport from #6998.
glasser pushed a commit that referenced this pull request Oct 7, 2022
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to version-4, this PR
will be updated.

⚠️⚠️⚠️⚠️⚠️⚠️

`version-4` is currently in **pre mode** so this branch has prereleases
rather than normal releases. If you want to exit prereleases, run
`changeset pre exit` on `version-4`.

⚠️⚠️⚠️⚠️⚠️⚠️

# Releases
## @apollo/server-integration-testsuite@4.0.0-rc.17

### Patch Changes

- Updated dependencies
\[[`233b44eea`](233b44e)]:
    -   @apollo/server@4.0.0-rc.17

## @apollo/server@4.0.0-rc.17

### Patch Changes

- [#6998](#6998)
[`233b44eea`](233b44e)
Thanks [@glasser](https://github.com/glasser)! - Fix a slow memory leak
in the usage reporting plugin (#6983).

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
glasser added a commit that referenced this pull request Oct 7, 2022
A data structure in the usage reporting plugin would get a new entry
each time the server's schema changed. Old entries would never be
deleted, though their values would be shrunk to a minimum size.

It seems that this was not good enough and is producing notable memory
leaks for some folks. So let's fix it!

The reason for the old behavior was to be really careful to never write
to a report that may have already been taken out of the map and sent.
Previously this was accomplished by having the main entry in the map
never change. Now this is accomplished by making sure that we never
write to the report any later than immediately (and synchronously) after
we pull it out of the map.

Fixes #6983. Backport from #6998.
@github-actions github-actions bot mentioned this pull request Oct 10, 2022
@bonnici
Copy link
Contributor

bonnici commented Oct 17, 2022

All looks good to me! Sorry for delayed response, just getting back from time off now.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
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.

None yet

2 participants