NIOTypedHTTPClientUpgradeHandler will write Upgrade request on handlerAdded if active#3473
Merged
Lukasa merged 5 commits intoapple:mainfrom Jan 14, 2026
Merged
Conversation
Lukasa
requested changes
Jan 9, 2026
Contributor
Lukasa
left a comment
There was a problem hiding this comment.
This is a good change, but needs a slight tweak to be a bit more defensive.
It is currently possible to crash this handler. To do it, you could write a test like the following:
- Add a handler to the pipeline that, when it receives
channelActive, will add the upgrade handler to the pipeline, and then forwards onchannelActive. - Activate the channel.
In this flow, the handler will activate itself on handlerAdded, but then receive channelActive and crash.
The solution here is to enhance the state machine to tolerate activating twice, and return none as the action for future activations.
Lukasa
approved these changes
Jan 14, 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.
NIOTypedHTTPClientUpgradeHandler.handlerAddedwill write upgrade request if the channel is already activeMotivation:
This has been added to make it easier to implement a websocket client that supports proxies. If the upgrade handler is added after the proxy connect has been processed previously nothing would happen.
Modifications:
NIOTypedHTTPClientUpgradeHandler.writeUpgradeRequest()function. Call this fromchannelActiveand also fromhandlerAddedif the channel is already active.testUpgradeHappensAfterHandlerAddedResult:
NIOTypedHTTPClientUpgradeHandler now also works if it is added to a channel after the channel is active