Skip to content

WebSockets not closed gracefully #1770

@Tratcher

Description

@Tratcher

Describe the bug

After the client and server have exchanged graceful WS Close messages, YARP isn't gracefully closing the connection. After a few seconds the client times out and closes the connection. This causes the client (E.g. Chrome) to report a WS error (1006) rather than a graceful close (1000).

To Reproduce

  1. Create a WebSocket connection through YARP
  2. Close it gracefully from both sides
  3. Observe a multi-second pause and then the client disconnects and may report an error

This reproduces with YARP running on Kestrel, HttpSys, and IIS Express. The client can be chrome, edge or even HttpClient, though that doesn't report an error.

It also reproduces in our WebSocket functional tests, causing them to take 1s or longer, vs a few ms when I tell YARP to cancel the request read.
https://github.com/microsoft/reverse-proxy/blob/b9f43dd4b383e7c2e1b222c0dd6587a848d88a56/test/ReverseProxy.FunctionalTests/WebSocketTests.cs#L26

I think the problem is here:
https://github.com/microsoft/reverse-proxy/blob/b9f43dd4b383e7c2e1b222c0dd6587a848d88a56/src/ReverseProxy/Forwarder/HttpForwarder.cs#L593

After the client and destination have exchanged close messages the destination closes the connection. YARP sees the response copy complete, but then waits for the request side to be closed from the client. Instead it should cancel the ongoing read.

Further technical details

Version: 1.1
Reported by an internal partner

Recommend we patch this in 1.1

Metadata

Metadata

Assignees

Labels

Type: BugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions