-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
reverse_proxy: h2 websocket stuck if client needs to send the first message and encode is enabled #6733
Comments
I suppose I can manually unwrap the response writer until no more unwrap can be done. And use this unwrapped response writer instead. What do you think @mholt ? |
h1 rfc, h2 rfc and h3 rfc all states that In websockets over h2 scenario, this is also true. As in all cases where websockets are involved. |
There seems to be some functionality in place to avoid encoding WebSocket requests: caddy/modules/caddyhttp/encode/encode.go Lines 400 to 407 in 57ae9c3
I think we should give all |
The h2 WebSocket requests aren't using the
|
This comment has been minimized.
This comment has been minimized.
I think for a non successful upgrade, |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
That header is created. Why do you say it's not?
Anyway, that's not relevant in this issue. |
My bad, missed it. |
Sounds reasonable 👍 |
With this merged, I noticed some of my websockets failed to connect while others succeed.
I disabled
encode
and found out now these requests connect successfully.The problem is that client requests contain the header
accept-encoding: gzip, deflate, br, zstd
, which is wrappedcaddy/modules/caddyhttp/encode/encode.go
Lines 155 to 160 in 9c0c71e
This response writer will write informational header immediately
caddy/modules/caddyhttp/encode/encode.go
Lines 250 to 252 in 9c0c71e
During websocket upgrade, for http1, the upgrade will write
101
status,caddy/modules/caddyhttp/reverseproxy/streaming.go
Line 122 in 9c0c71e
which will be flushed to the client immediately.
However, for h2, although
FlushError
is calledcaddy/modules/caddyhttp/reverseproxy/streaming.go
Line 111 in 9c0c71e
response code is
200
same as any other status that indicates success. Because we want to determine if the response can be encoded, this code is stored and flushed later if there is any data from the upstream and we can be sure whether the response can be encodedcaddy/modules/caddyhttp/encode/encode.go
Lines 262 to 269 in 9c0c71e
If the websocket transport a protocol that server sends response first, it is OK as that will cause the status and data to be sent. But if the client sends data first, it won't happen because the response will never be sent, and client thinks the handshake didn't finish.
For now, I created a matcher to ignore encoding for h2 websocket upgrade
But I think an elegant solution should be implemented.
The text was updated successfully, but these errors were encountered: