Add idle body write detection to Netty HTTP client#6844
Open
Add idle body write detection to Netty HTTP client#6844
Conversation
92c38d9 to
03c9ac1
Compare
03c9ac1 to
61a1147
Compare
zoewangg
commented
Apr 7, 2026
Comment on lines
+296
to
+298
| channel.pipeline().addBefore(httpStreamsName, WRITE_IDLE_STATE_HANDLER_NAME, | ||
| new IdleStateHandler(0, context.configuration().writeTimeoutMillis(), 0, | ||
| TimeUnit.MILLISECONDS)); |
Contributor
Author
There was a problem hiding this comment.
We have to give it a dedicated name because we use IdleStateHandler elsewhere and removing the handler based on class type would cause those handlers to be removed prematurely
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.
Motivation and Context
When using a request body publisher that is slow or unable to produce data, the connection may stay open for a long time after headers are sent. The existing
WriteTimeoutHandlerdoesn't detect this because nowrite()operation is scheduled for it to time out on.Modifications
WriteIdleTimeoutHandlerthat listens forWRITER_IDLEevents from Netty'sIdleStateHandlerand proactively closes the connection with a descriptive error messageIdleStateHandler+WriteIdleTimeoutHandlerto the channel pipeline inNettyRequestExecutor.writeRequest(), placed after the SSL handler (beforeHttpStreamsClientHandler) to avoid TLS record writes resetting the idle timerHandlerRemovingChannelPoolListenerto clean up the new handlers on channel releaseTesting
WriteIdleTimeoutHandlerTest— unit tests for the handler: verifies idle event fires exception and closes channel, non-writer events are ignored, and duplicate events don't fire twiceWriteIdleTimeoutTest— integration test with a TLS server and a stalled body publisher that never produces data, verifying the idle timeout fires within the expected windowHandlerRemovingChannelPoolListenerTest— updated to verify new handlers are cleaned up on channel releaseTypes of changes
Checklist
mvn clean install -pl :netty-nio-clientsucceedsLicense