Fix Netty ByteBuf leak in GatewayServerErrorInjector fault injection delay paths#48880
Open
jeet1995 wants to merge 1 commit intoAzure:mainfrom
Open
Fix Netty ByteBuf leak in GatewayServerErrorInjector fault injection delay paths#48880jeet1995 wants to merge 1 commit intoAzure:mainfrom
jeet1995 wants to merge 1 commit intoAzure:mainfrom
Conversation
0725648 to
d360362
Compare
…delay paths When fault injection simulates a response delay, the real HTTP response body was discarded without draining its ByteBuf content. Under HTTP/2, this causes ByteBuf leaks that accumulate on the long-lived parent channel. Two leak paths fixed: - delay >= timeout: doOnNext drains body before delayElement buffers it - delay < timeout: doOnDiscard releases body if downstream cancels during delay Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
d360362 to
baf040e
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a Netty ByteBuf leak in the Cosmos fault-injection layer when simulating gateway response delays under HTTP/2, by ensuring the real response body is drained/released even when the response is discarded or dropped on cancellation.
Changes:
- Drain and release the response body before delaying when the injected delay exceeds the effective response timeout.
- Release the response body when
delayElementdiscards a bufferedHttpResponsedue to downstream cancellation (viadoOnDiscard). - Add a helper (
releaseResponseBody) to centralize the drain/release logic.
Member
Author
|
/azp run java - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
tvaron3
approved these changes
Apr 20, 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.
Description
Fixes Netty ByteBuf leaks in
GatewayServerErrorInjectorwhen fault injection simulates response delays under HTTP/2.Root Cause
When fault injection simulates a response delay via
delayElement, the real HTTP response body was discarded without draining its ByteBuf content. Under HTTP/1.1, connection closure masks this because all ByteBufs are released when the channel closes. Under HTTP/2, the parent connection stays pooled and the undrained ByteBufs accumulate on the parent channel's allocator — causing growing memory leaks.Fix
Two leak paths in
injectGatewayServerResponseError:delay >= timeout.then(Mono.error(ReadTimeoutException))— body is never consumeddoOnNextdrains and releases the body beforedelayElementbuffers the responsedelay < timeoutdelayElement(e.g., an outer timeout fires),delayElementsilently drops the buffered HttpResponse without emitting itdoOnDiscard(HttpResponse.class, ...)catches that discard and releases the body ByteBuf to prevent leaksBoth paths call
releaseResponseBody()which subscribes to the body flux andReferenceCountUtil.safeRelease()s each ByteBuf — consistent with existing patterns inReactorNettyClient.java.Testing
PerPartitionCircuitBreakerE2ETests(thin-client + HTTP/2 path)Related