This repository was archived by the owner on Feb 24, 2026. It is now read-only.
forked from adamfisk/LittleProxy
-
Notifications
You must be signed in to change notification settings - Fork 15
Fix bytebuf memory leak when a request is canceled #62
Merged
viacheslav-fomin-main
merged 2 commits into
verygoodsecurity:vgs-edition
from
viacheslav-fomin-main:defect/bb-leak-fix
Feb 28, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ | |
| import io.netty.handler.codec.http.HttpVersion; | ||
| import io.netty.handler.timeout.IdleStateHandler; | ||
| import io.netty.handler.traffic.GlobalTrafficShapingHandler; | ||
| import io.netty.util.ReferenceCounted; | ||
| import io.netty.util.ReferenceCountUtil; | ||
| import io.netty.util.concurrent.EventExecutorGroup; | ||
| import io.netty.util.concurrent.Future; | ||
| import io.netty.util.concurrent.GenericFutureListener; | ||
|
|
@@ -355,34 +355,26 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) { | |
| final HttpRequest httpRequest = (HttpRequest) msg; | ||
|
|
||
| if (ProxyUtils.isChunked(httpRequest)) { | ||
| process(ctx, httpRequest); | ||
| process(ctx, httpRequest, true); | ||
| } else { | ||
| if (httpRequest instanceof ReferenceCounted) { | ||
| LOG.debug("Retaining reference counted message"); | ||
| ((ReferenceCounted) msg).retain(); | ||
| } | ||
| ReferenceCountUtil.retain(httpRequest); | ||
|
|
||
| proxyServer.getMessageProcessingExecutor() | ||
| .execute(wrapTask(() -> { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need to move |
||
| .execute(() -> { | ||
| try { | ||
| process(ctx, httpRequest); | ||
| wrapTask(() -> process(ctx, httpRequest, false)).run(); | ||
| } catch (Exception e) { | ||
| ctx.fireExceptionCaught(e); | ||
| } finally { | ||
| if (httpRequest instanceof ReferenceCounted) { | ||
| LOG.debug("Retaining reference counted message"); | ||
| ((ReferenceCounted) httpRequest).release(); | ||
| } | ||
| ReferenceCountUtil.release(httpRequest); | ||
| } | ||
| })); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| private void process(ChannelHandlerContext ctx, HttpRequest httpRequest) { | ||
| private void process(ChannelHandlerContext ctx, HttpRequest httpRequest, boolean chunked) { | ||
|
|
||
| boolean authenticationRequired = false; | ||
| HttpResponse shortCircuitResponse = null; | ||
| authenticationRequired = authenticationRequired(httpRequest); | ||
| boolean authenticationRequired = authenticationRequired(httpRequest); | ||
|
|
||
| if (authenticationRequired) { | ||
| LOG.debug("Not authenticated!!"); | ||
|
|
@@ -398,9 +390,7 @@ private void process(ChannelHandlerContext ctx, HttpRequest httpRequest) { | |
| filterInstance = proxyServer.getFiltersSource().filterRequest(currentRequest, ctx); | ||
| } finally { | ||
| // releasing a copied http request | ||
| if (currentRequest instanceof ReferenceCounted) { | ||
| ((ReferenceCounted) currentRequest).release(); | ||
| } | ||
| ReferenceCountUtil.release(currentRequest); | ||
| } | ||
| if (filterInstance != null) { | ||
| currentFilters = filterInstance; | ||
|
|
@@ -409,17 +399,24 @@ private void process(ChannelHandlerContext ctx, HttpRequest httpRequest) { | |
| } | ||
|
|
||
| // Send the request through the clientToProxyRequest filter, and respond with the short-circuit response if required | ||
| shortCircuitResponse = currentFilters.clientToProxyRequest(httpRequest); | ||
|
|
||
| } | ||
| final HttpResponse shortCircuitResponse = currentFilters.clientToProxyRequest(httpRequest); | ||
|
|
||
| if (!authenticationRequired) { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refactored |
||
| if (httpRequest instanceof ReferenceCounted) { | ||
| LOG.debug("Retaining reference counted message"); | ||
| ((ReferenceCounted) httpRequest).retain(); | ||
| if (chunked) { | ||
| ctx.fireChannelRead(new UpstreamConnectionHandler.Request(httpRequest, shortCircuitResponse)); | ||
| } else { | ||
| ReferenceCountUtil.retain(httpRequest); | ||
| channel.eventLoop().execute(() -> { | ||
| try { | ||
| wrapTask(() -> | ||
| ctx.fireChannelRead( | ||
| new UpstreamConnectionHandler.Request(httpRequest, shortCircuitResponse)) | ||
| ).run(); | ||
| } finally { | ||
| ReferenceCountUtil.release(httpRequest); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| ctx.fireChannelRead(new UpstreamConnectionHandler.Request(httpRequest, shortCircuitResponse)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
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
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
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.
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.
we need it so the message is not released when we use
chunks(when we do not use custom executor)