Skip to content
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

Refactor websocket handler to protect against concurrent writes #811

Closed
wants to merge 1 commit into from

Conversation

pcj
Copy link

@pcj pcj commented Dec 11, 2020

  1. Move websocket http handler code from wrapper.go to websocket_handler.go.
  2. Added websocket_client.go and websocket_clienthub.go to manage concurrent requests.
  3. Broke out the reader / writer structs into separate files.
  4. Refactored webSocketResponseWriter to send messages to the client hub rather than write to the websocket directly.

Still working on this. Needs a proper test.

Closes #713

@improbable-prow-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign
You can assign the PR to them by writing /assign in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment


func (w *webSocketResponseWriter) writeMessage(b []byte) error {
w.client.send <- b
return nil // TODO(pcj): is there a need to propagate write errors?
Copy link
Contributor

Choose a reason for hiding this comment

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

I think at best we'll end up logging them, so we probably can just log it in the websocket writer.

Comment on lines +98 to +101
// Flush implements the https://golang.org/pkg/net/http/#Flusher interface.
func (w *webSocketResponseWriter) Flush() {
// no-op
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this always a no-op, or can we coerce the websocket writer to implement this?

Copy link
Contributor

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

Nice work, really liking where this is going. I'm wondering, if we're using significant amounts of the code from the gorilla library, should we include a copy of their license in this directory too? Their license isn't in conflict with ours, I hope?

@johanbrandhorst
Copy link
Contributor

FYI #815 was just opened as an alternative fix for the underlying issue.

@pcj
Copy link
Author

pcj commented Dec 11, 2020

#815 looks like a simpler change. I'll test that one out in my environment and if it seems OK, will plan to close this PR. I did make some significant inroads on a test suite for the websocket functionality; I can contribute that as a separate PR.

@johanbrandhorst
Copy link
Contributor

Thanks a lot, Paul 🙏🏻, that sounds good.

@pcj pcj closed this Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

grpcwebproxy: "panic: concurrent write to websocket connection"
3 participants