IIS doesn't close WebSocket connections cleanly
I apologize if this isn't the right place to report an issue, but the IIS Feedback page is down.
It appears that IIS isn't closing WebSocket connections properly.
According to the WebSocket specification, the peer closing the connection is supposed to wait for the other peer to acknowledge before terminating the connection.
When IIS receives a close frame from a proxied server, it terminates the connection immediately without waiting for the client to acknowledge.
This causes an issue on some browsers. For example:
- Chrome on Windows overrides the close code to 1006
- Firefox throws an error
The issues can be observed with both WebSockets (ws://) and Secure WebSockets (wss://).
I've created a minimal Node.JS WebSocket server that reproduces the issue on IIS.
Here's a Wireshark trace showing the issue (test 3):
Connection is initiated in segment 93. The server then decides to close the connection in segment 94. But instead of waiting for the reponse from the browser and gracefully terminating the connection with a FIN, it abruptly terminates the connection with a RST in segment 95.
The same MRE (test 3) running behind a nginx proxy gives the expected result:
The server closes the connection in segment 24, waits for the client response in segment 26 then gracefully terminates the connection with a FIN in segment 27.
Environment:
Microsoft Windows Server 2022 Datacenter Azure Edition
Windows 10.0.20348 Build 20348 - Version 21H2 (OS Build 20384.3453)
Internet Information Services (Version 10.0.20348.1)
URL Rewrite 2.1
Application Request Routing (ARR) 3.0