Fix memory leak on initial requests with HttpObjectAggregator#351
Merged
Conversation
This was referenced Feb 27, 2017
|
we have verified that this resolves #348. lgtm! |
|
connectionSucceeded will release request,but when connectionfailed happen, it must be also release request! @jekh |
asolntsev
added a commit
to LittleProxy/LittleProxy
that referenced
this pull request
Aug 8, 2022
This change continues PR adamfisk/LittleProxy#351 - it seems it didn't cover all possible cases.
|
@linking12 Hi. I was investigating issue LittleProxy/LittleProxy#131 and encountered your comment. Can you review my PR that hopefully should fix the issue? |
asolntsev
added a commit
to LittleProxy/LittleProxy
that referenced
this pull request
Aug 9, 2022
This change continues PR adamfisk/LittleProxy#351 - it seems it didn't cover all possible cases.
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.
This PR should fix issue #348. The change is very simple: initial HttpRequests are released if they are ReferenceCounted. However, the reasoning is complicated and requires a non-trivial understanding of netty reference counting, so here's a more detailed explanation of what's happening:
When
HttpObjectAggregatoris in the pipeline, it generatesReferenceCountedFullHttpRequests (since they have content as well as the request headers). Whereas, whenHttpObjectAggregatoris not in the pipeline, theHttpRequestdoes not contain body content and therefore is notReferenceCounted.When the
ProxyToServerConnection#write()method is called, it always increments ReferenceCounted objects, since netty will automatically decrement them when they are written to the server (and we want to keep them around, since our ClientToProxyConnection will also try to clean them up). Generally this works fine, even for FullHttpRequests, but it breaks when dealing with the initial request.For initial HTTP messages, which are eventually written to the server, the
ProxyToServerConnection#write()method is called twice: first when the server is disconnected, and then again after the connection is complete. This causes theReferenceCountedobject to be.retain()ed twice, but only released by netty once (when it is actually written to the server).For initial HTTPS messages (always a CONNECT), which are not written to the server at all, they are only
.retain()ed once, when the server is disconnected, then "dropped", since the CONNECT is never written to the upstream server. But since the FullHttpRequest was already retained by the write() method, it must be manually released.