Skip to content

fix(coderd): disable websocket compression for startup logs on Safari #8070

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

Closed
wants to merge 1 commit into from

Conversation

mafredri
Copy link
Member

There is a problem with Safari and using compression with fragmented
messages. Unfortunately nhooyr/websocket does not support controlling
fragmentation or buffer sizes, so we have to resort to either sending
fixed size payloads or disabling compression for Safari. Given the
variable size of log lines and how well they compress, we choose to
disable compression for Safari.

Before this fix, we may see the following error when the API a large
payload of logs (confirmed using Safari 16.5):

WebSocket connection to 'wss://.../startup-logs?follow&after=0' failed: The operation couldn’t be completed. Protocol error

See:

// * https://github.com/nhooyr/websocket/issues/218
// * https://github.com/gobwas/ws/issues/169
ua := strings.ToLower(r.Header.Get("User-Agent"))
safari := strings.Contains(ua, "safari") && !strings.Contains(ua, "chrome") && !strings.Contains(ua, "android")
Copy link
Member Author

Choose a reason for hiding this comment

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

Probably need to fix this check, I didn't really investigate its completeness.

Copy link
Member Author

Choose a reason for hiding this comment

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

On second thought, it seems like a futile effort to detect browser via UA (isn't that the point these days). Should we just always disable compression? (It's really unfortunate, but since we don't control the length of log lines, a single log entry could be too big.)

Copy link
Member

Choose a reason for hiding this comment

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

+1

I don't think that this check will be bullet-proof, so maybe just set the websocket.CompressionDisabled. If we want to keep the User Agent detection logic, I would look for a Go library to do this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed. I think it'd be more robust to detect the browser in the.. browser 😄, so perhaps we could do it in the site package via JS and have the client request compression enabled/disabled. We already include the ua-parser-js library there (for audit logs), so it won't add bloat.

As can be seen here: https://faisalman.github.io/ua-parser-js/, it works well.

@mafredri
Copy link
Member Author

Closing in favor of #8087.

@mafredri mafredri closed this Jun 19, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jun 19, 2023
@github-actions github-actions bot deleted the mafredri/fix-safari-startup-log-streaming branch December 17, 2023 00:12
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.

2 participants