-
Notifications
You must be signed in to change notification settings - Fork 656
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
Client-Server connection not established using Swift-NIO #3064
Comments
Thanks for filing this issue. |
The server is also using Swift-NIO (the same version as the client as above). The connection was working fine with Xcode 15.1.0, but after upgrading to Xcode 16.1.0 at the client end (for SDK 18 support), we started seeing the upgraderDeniedUpgrade error. |
Are any errors printed on the server side? |
We do not see any errors logged on the server side. Please let us know if we need to add any specific logging code in a particular class or method to capture the required logs. Currently, our WebSocket server is implemented based on the following sample code: We have overridden the channelActive method of the ChannelInboundHandler interface in the HTTPHandler class. We observe that the control reaches this method, and we can log the client address when it connects. However, the connection gets disconnected shortly thereafter. Additionally, we verified that the connection fails during client-side verification, specifically in the shouldAllowUpgrade method of the following class: NIOWebSocketClientUpgrader.swift It seems like this method is returning false. Note: This works in the simulator but does not if the app runs on devices. |
Ok, let's add some debugging. Add this class: final class ErrorHandler: ChannelInboundHandler {
typealias InboundIn = Any
typealias InboundOut = Any
func errorCaught(context: ChannelHandlerContext, error: any Error) {
// Replace this print with any logging you'd prefer
print(error)
context.fireErrorCaught(error)
}
} Then, amend swift-nio/Sources/NIOWebSocketServer/main.swift Lines 222 to 224 in 124119f
return channel.pipeline.configureHTTPServerPipeline(withServerUpgrade: config).flatMap {
channel.pipeline.addHandler(httpHandler)
}.flatMap {
channel.pipeline.addHandler(ErrorHandler())
} |
I'm also getting upgraderDeniedUpgrade with xcode 16.2 on macOS 15.3, whatever the websocket server I try to connect to. However, the same code works fine compiled from debian 12 running swift 6.0.3. I'm using the WebSocket.swift package. If I manually concatenate the request key and the magic websocket handshake GUID, then sha1 then base64 encode the resulting bytes, I do get the expected answer. However, the value returned by I see the base64 encoded string is being computed with a custom implementation of base64 that was removed with swift NIO 2.59.0. I'll try upgrading WebSocket.swift to use a more recent version of SwiftNIO tomorrow. |
I can confirm the issue is fixed on my side by using a more recent version of SwiftNIO... |
@msklywenn Thank you, can this be closed? |
We are experiencing an issue where the client and server connection is not being established. We are using the Swift-NIO library with the following versions:
This is the reference code for the client. the issue the happening after updating Xcode version - 15.1.0 to 16.1.0 for SDK 18 support.
https://github.com/apple/swift-nio/blob/2.40.0/Sources/NIOWebSocketClient/main.swift
SwiftNIO: 2.40.0
SwiftNIOHTTP1: 2.40.0
SwiftNIOWebSocket: 2.40.0
SwiftNIOSSL: 2.19.0
Client-side: Xcode 16.1.0
Expected Behavior
The client should successfully connect to the server without issues.
Actual Behavior
We are getting the upgraderDeniedUpgrade error from errorCaught method of class HTTPInitialRequestHandler
The connection between the client and server fails without any clear errors. We have verified that both sides are running compatible Swift-NIO above versions. any guidance, suggestions, or help diagnosing this issue would be greatly appreciated.
The text was updated successfully, but these errors were encountered: