swift-nio icon indicating copy to clipboard operation
swift-nio copied to clipboard

Failed WebSocket upgrade throws `inappropriateOperationForState` error

Open adam-fowler opened this issue 1 year ago • 2 comments

Expected behavior

WebSocket client should call notUpgradingCompletionHandler from NIOTypedHTTPClientUpgradeConfiguration when WebSocket server refuses a connection.

Actual behavior

WebSocket upgrade throws inappropriateOperationForState error

Steps to reproduce

This can be easily reproduced using the WebSocket samples that come with SwiftNIO

  1. Edit the shouldUpgrade closure of NIOTypedWebSocketServerUpgrader in NIOWebSocketServer/Server.swift line 82 to be
channel.eventLoop.makeSucceededFuture(nil)`.
  1. Run NIOWebSocketServer sample
  2. Run NIOWebSocketClient sample

SwiftNIO version/commit hash

Swift version 5.10-dev (LLVM e8e5be8d5b39f46, Swift 99e9db868aefd99) Target: x86_64-unknown-linux-gnu

adam-fowler avatar Jan 26 '24 09:01 adam-fowler

Thanks for filing this. I will take a look!

FranzBusch avatar Jan 26 '24 09:01 FranzBusch

One of the reasons I was receiving inappropriateOperationForState was the server wasn't returning a response to the WebSocket upgrade request, it was just closing the connection. If I return a response everything is ok.

I guess we still shouldn't be receiving a inappropriateOperationForState error though even if the server closes the connection

adam-fowler avatar Mar 19 '24 08:03 adam-fowler