-
Notifications
You must be signed in to change notification settings - Fork 47
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: memory leak by AbortController #172
Merged
yusukebe
merged 4 commits into
honojs:main
from
usualoma:fix/abort-controller-memory-leak
May 30, 2024
Merged
fix: memory leak by AbortController #172
yusukebe
merged 4 commits into
honojs:main
from
usualoma:fix/abort-controller-memory-leak
May 30, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Due to the nodejs implementation, passing an object to `abort()` will cause a memory leak, so pass a string
@yusukebe Would you please review? |
|
yes |
This branch fixed my original bug! Thank you! |
yusukebe
approved these changes
May 30, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Hi @usualoma ! Thank you for the fix and the test is great! I'll merge this now. |
nicolewhite
referenced
this pull request
in autoblocksai/cli
Jun 4, 2024
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [@hono/node-server](https://github.com/honojs/node-server) | [`1.11.1` -> `1.11.2`](https://renovatebot.com/diffs/npm/@hono%2fnode-server/1.11.1/1.11.2) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@hono%2fnode-server/1.11.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@hono%2fnode-server/1.11.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@hono%2fnode-server/1.11.1/1.11.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@hono%2fnode-server/1.11.1/1.11.2?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>honojs/node-server (@​hono/node-server)</summary> ### [`v1.11.2`](https://github.com/honojs/node-server/releases/tag/v1.11.2) [Compare Source](https://github.com/honojs/node-server/compare/v1.11.1...v1.11.2) #### What's Changed - ci: include tests for node 22 version by [@​Jayllyz](https://github.com/Jayllyz) in [https://github.com/honojs/node-server/pull/170](https://github.com/honojs/node-server/pull/170) - fix: memory leak by AbortController by [@​usualoma](https://github.com/usualoma) in [https://github.com/honojs/node-server/pull/172](https://github.com/honojs/node-server/pull/172) #### New Contributors - [@​Jayllyz](https://github.com/Jayllyz) made their first contribution in [https://github.com/honojs/node-server/pull/170](https://github.com/honojs/node-server/pull/170) **Full Changelog**: honojs/node-server@v1.11.1...v1.11.2 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on Monday" in timezone America/Chicago, Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/autoblocksai/cli). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zNzcuOCIsInVwZGF0ZWRJblZlciI6IjM3LjM3Ny44IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This was referenced Sep 17, 2024
This was referenced Sep 18, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #171, honojs/hono#2816
Two issues needed to be corrected in this issue.
incoming.destroyed
is true for all POST requestsThe documentation says "Deprecated. check request.destroyed instead."
However, incoming was flagged for “autodestroy" and
incoming.destroy()
was always called when the request body was read to the end. In other words,.abort()
was always called in POST requests. POST requests complete successfully, so there are no major problems, but I think it was not a good behaviour.https://github.com/nodejs/node/blob/c0c598d753d5ce7e1721215c6e6254dc02c023a8/lib/internal/streams/readable.js#L1690-L1716
As errored seemed more suitable for our application, I decided to use it.
.abort()
(call without arguments) causes memory leakThe real problem of memory leaks is here, which was an interesting situation.
Calling
abort()
with no arguments uses an instance ofDOMException
, but (presumably) this object is referenced including its children and grandchildren, so it appears that a cycle of references occurs and a instance of AbortController cannot be freed.https://github.com/nodejs/node/blob/c0c598d753d5ce7e1721215c6e6254dc02c023a8/lib/internal/abort_controller.js#L395-L397
https://github.com/nodejs/node/blob/c0c598d753d5ce7e1721215c6e6254dc02c023a8/lib/internal/abort_controller.js#L368-L378
For "reason", not only for
DOMException
, it seems to be necessary to pass a string, as specifying anObject
seems to cause a memory leak.tsconfig.json
In order to use
FinalisationRegistry
in server.test.ts, the settings in tsconfig.json needed to be reflected in server.test.ts, so tsconfig.json was changed.32c09a9