Skip to content

Commit

Permalink
Ensure we release FullHttpContent instances when unlinking
Browse files Browse the repository at this point in the history
  • Loading branch information
artgon authored and argha-c committed Apr 14, 2023
1 parent f2d7600 commit 22ba0e9
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ private Channel unlinkFromOrigin() {
return origCh;
}

private void releasePartialResponse(HttpResponse partialResponse) {
if (partialResponse != null && ReferenceCountUtil.refCnt(partialResponse) > 0) {
ReferenceCountUtil.safeRelease(partialResponse);
}
}

public void finish(boolean error) {
final Channel origCh = unlinkFromOrigin();

Expand Down Expand Up @@ -721,6 +727,7 @@ public void responseFromOrigin(final HttpResponse originResponse) {
methodBinding.bind(() -> processResponseFromOrigin(originResponse));
} catch (Exception ex) {
unlinkFromOrigin();
releasePartialResponse(originResponse);
LOG.error("Error in responseFromOrigin", ex);
channelCtx.fireExceptionCaught(ex);
}
Expand Down Expand Up @@ -855,6 +862,7 @@ protected void handleOriginNonSuccessResponse(final HttpResponse originResponse,
startedSendingResponseToClient, zuulRequest.hasCompleteBody(), zuulRequest.getMethod());
//detach from current origin.
unlinkFromOrigin();
releasePartialResponse(originResponse);

// ensure body reader indexes are reset so retry is able to access the body buffer
// otherwise when the body is read by netty (in writeBufferedBodyContent) the body will appear empty
Expand Down

0 comments on commit 22ba0e9

Please sign in to comment.