-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
reverseproxy: Mask the WS close message when we're the client #5199
Conversation
Tested it with my NodeJS app, seems to work! I see both the client and server closing the connection when I stop Caddy, and the error went away on the server. |
I just notice the same on my server. It crashed the whole application and require hard restart to resume the upstream. |
@climba03003 could you try out a build with this PR to confirm the fix works for you too? What made you find this issue, is this just an insane coincidence?? I only just discovered this problem a few hours ago. |
I am migrating my company from
I am using container for the application, it will be a bit hard to use a custom build. |
No, it should be super easy, actually. FROM caddy:2.6.2-builder AS builder
# TODO: Temporarily using a commit from https://github.com/caddyserver/caddy/pull/5199
# until that pull request is merged.
RUN xcaddy build 775e352b6feb6f85f2066a8933d3e0e9751b32a0
FROM caddy:2.6.2-alpine
COPY --from=builder /usr/bin/caddy /usr/bin/caddy |
Good to know that, I will report back after the reporter test. |
Seems it is not fixed in my end. I might need to patch the outside stateDiagram
[*] --> Caddy(2.6.2)
state Container {
Caddy(775e352b6feb6f85f2066a8933d3e0e9751b32a0) --> Node.JS
Node.JS --> [*]
}
Caddy(2.6.2) --> Container
|
Probably. It depends which one is reloaded or restarted, as that's the one the close frame will be sent from. |
After running of 3 days, it does solve the issue. Thanks. |
Thanks! We'll merge as soon as Matt has a chance to give this a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for figuring this out, Francis! 😁
While testing a NodeJS app of mine, I noticed that since our changes to the proxy to send a WebSocket close frame, when Caddy would close first, we would see
RangeError: Invalid WebSocket frame: MASK must be set
in our logs from https://github.com/websockets/ws.After some investigation, it looks like when we're the "client" (i.e. the upstream half of the proxy, whereas for the downstream half we act as the "server"), we need to mask the message according to https://www.rfc-editor.org/rfc/rfc6455#section-5.3.
I copied the
maskKey
andmaskBytes
code from https://github.com/websockets/ws as noted in code comments.Needs some testing to make sure this still works correctly.