Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Websocket client upgrade failure #2659

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Sources/NIOHTTP1/NIOTypedHTTPClientUpgradeHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,19 @@ public final class NIOTypedHTTPClientUpgradeHandler<UpgradeResult: Sendable>: Ch
public func handlerRemoved(context: ChannelHandlerContext) {
switch self.stateMachine.handlerRemoved() {
case .failUpgradePromise:
self.upgradeResultPromise.fail(ChannelError.inappropriateOperationForState)
// Make sure the completion handler is called on the failed upgrade path
self.notUpgradingCompletionHandler(context.channel)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This We cannot run the notUpgradingCompletionHandler in all cases where the state machine returns failUpgradePromise right now. What we should rather do is add a case to the HandlerRemovedAction from the state machine and return that from the states where we know that running the notUpgradingCompletionHandler is correct. In detail, running the notUpgradingCompletionHandler while we are in the state upgrading or unbuffering doesn't seem correct to me.

.hop(to: context.eventLoop)
.whenComplete { result in
switch result {
case .success(let value):
// Expected upgrade failure without error
self.upgradeResultPromise.succeed(value)
case .failure(let error):
// Unexpected upgrade failure with error
self.upgradeResultPromise.fail(error)
}
}
case .none:
break
}
Expand Down