apple / swift-nio

Event-driven network application framework for high performance protocol servers & clients, non-blocking.
https://swiftpackageindex.com/apple/swift-nio/documentation
Apache License 2.0
8k stars 652 forks source link

Failed WebSocket upgrade throws `inappropriateOperationForState` error #2631

Open adam-fowler opened 10 months ago

adam-fowler commented 10 months ago

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)`.
  2. Run NIOWebSocketServer sample
  3. Run NIOWebSocketClient sample

SwiftNIO version/commit hash

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

FranzBusch commented 10 months ago

Thanks for filing this. I will take a look!

adam-fowler commented 8 months ago

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