Repository navigation
fix(cronet_http): UrlRequest leak - #2129
Open
brianquinlan wants to merge 5 commits into
Open
brianquinlan wants to merge 5 commits into
brianquinlan wants to merge 5 commits into
Conversation
brianquinlan
marked this pull request as draft
November 20, 2026 05:24
There was a problem hiding this comment.
Code Review
This pull request fixes memory and JNI global reference leaks across request lifecycles and abortable uploads in cronet_http. It introduces the _ActiveUrlRequest class to manage the lifecycle of jb.UrlRequest global references, preventing leaks and double-releases. Additionally, it adds validation to throw a ClientException when a response Content-Length header overflows a 64-bit integer. Comprehensive integration tests have been added to verify these memory leak fixes and header overflow handling. There are no review comments, so I have no feedback to provide.
brianquinlan
marked this pull request as ready for review
November 20, 2026 22:02
liamappelbe
approved these changes
Nov 23, 2026
This file contains hidden or 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
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 #2124
Fixes #1919
There were two issues before:
This would keep
cronetRequestalive beyond the lifetime of thesendmethod if the abort was never triggered.onCancelinonResponseStartedclosed overurlRequest:This mean that it could not be cleaned-up by the arena.
I fixed this by creating a class (
_ActiveUrlRequest) that owns theUrlRequestand releases it as soon as any finishing code path indicates that we are done with it, i.e. request succeeded, request failed, request cancelled, request aborted. So now we only close over_ActiveUrlRequestwhich, if the request has already finished, will just contain a null reference to aUrlRequest.I added a conformance test for this sort of leak. They fail for
package:cronet_httpwithout this fix but they aren't very convincing for desktop implementations, which can allocate 10s of GiB of memory without any issue. I expect to improve those tests in the future. They are also slow - maybe I'll make an independent workflow for them.Contribution guidelines:
dart format.Many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.
Note: The Dart team is trialing Gemini Code Assist. Don't take its comments as final Dart team feedback. Use the suggestions if they're helpful; otherwise, wait for a human reviewer.