Skip to content

feat: automatically use websockets if DERP upgrade is unavailable #6381

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

Merged
merged 3 commits into from
Mar 1, 2023

Conversation

kylecarbs
Copy link
Member

@kylecarbs kylecarbs commented Feb 28, 2023

This might be our biggest hangup for deployments at the moment...

Load balancers do not support the DERP protocol by default (and many do not at all), so many of our prospects and customers run into failing workspace connections. After the first DERP connection HTTP response with a non http.StatusSwitchingProtocols response code (and <500), we will begin using WebSockets instead of DERP. It will never attempt to switch back for now.

In a future contribution, a warning will appear by the agent if it was forced to use WebSockets instead of DERP.

Depends on coder/tailscale#8

Related #6372

@kylecarbs kylecarbs requested review from mafredri and bpmct February 28, 2023 20:48
@kylecarbs kylecarbs self-assigned this Feb 28, 2023
This might be our biggest hangup for deployments at the moment...

Load balancers by default do not support the DERP protocol, so many
of our prospects and customers run into failing workspace connections.
This automatically swaps to use WebSockets, and reports the reason to
coderd.

In a future contribution, a warning will appear by the agent if it was
forced to use WebSockets instead of DERP.
@kylecarbs
Copy link
Member Author

@mafredri I'm going to wait to merge this until you approve... I've brought too many race conditions into this code to risk introducing more 😅😅😅

@bpmct
Copy link
Member

bpmct commented Mar 1, 2023

Resolves #6375

@deansheather deansheather self-requested a review March 1, 2023 17:13
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only a few things stood out, but other than that this looks good, nice change!

// speak WebSockets (they still assumed DERP's binary framing). So to distinguish
// clients that actually want WebSockets, look for an explicit "derp" subprotocol.
if up != "websocket" || !strings.Contains(r.Header.Get("Sec-Websocket-Protocol"), "derp") {
base.ServeHTTP(w, r)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we log here to better understand why it may not be working? (E.g. future bugs.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so because this could be spammy.

@kylecarbs kylecarbs enabled auto-merge (squash) March 1, 2023 21:48
@kylecarbs kylecarbs force-pushed the derpwebsocketswap branch from 91fbf09 to b830fad Compare March 1, 2023 22:00
@kylecarbs kylecarbs merged commit 1724cbf into main Mar 1, 2023
@kylecarbs kylecarbs deleted the derpwebsocketswap branch March 1, 2023 22:18
@github-actions github-actions bot locked and limited conversation to collaborators Mar 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants