grpc-web icon indicating copy to clipboard operation
grpc-web copied to clipboard

Can't increase the default nhooyr web socket read limit

Open bryanmcgrane opened this issue 3 years ago • 4 comments

I'm currently using the bi-directional streaming capabilities of this library in order to stream images from a web browser to my Go backend. The issue issue is, the nhooyr web socket library has a default maximum message size of 32769 bytes.

When I send an image larger than that size, I run into an error that is thrown by this check in the nhooyr library: https://github.com/nhooyr/websocket/blob/e4c3b0f8168d619c279822ab882b8f15717041af/ws_js.go#L112

I have a hack working now that calls SetReadLimit in wrapper.go at line 160:

// wrapper.go
func (w *WrappedGrpcServer) HandleGrpcWebsocketRequest(resp http.ResponseWriter, req *http.Request) {

	wsConn, err := websocket.Accept(resp, req, &websocket.AcceptOptions{
		InsecureSkipVerify: true, // managed by ServeHTTP
		Subprotocols:       []string{"grpc-websockets"},
	})

	wsConn.SetReadLimit(4e6)

	if err != nil {
		grpclog.Errorf("Unable to upgrade websocket request: %v", err)
		return
	}

       // etc
}

This is obviously not a permanent solution, as its not at all configurable. Is there a way I can configure this property or will it require a code change? Thank you for your help!

bryanmcgrane avatar Jul 08 '21 00:07 bryanmcgrane

Hi Bryan, thanks for your issue! Yeah this looks like something we should support, but it will probably require a code change. I expect we ought to be able to use the existing configuration options pattern to add an option for this setting, both for the in-process and standalone proxies. Would you be willing to help contribute this?

johanbrandhorst avatar Jul 08 '21 15:07 johanbrandhorst

@johanbrandhorst I have a branch with the working changes, but I'm unable to push to the repo - am seeing access denied. Can you grant me access to push my branch? Thanks!

bryanmcgrane avatar Jul 08 '21 15:07 bryanmcgrane

You'll need to create a fork of the repo so you can push and create a pull request from the fork, I don't have the permission to make you a contributor on the repository.

johanbrandhorst avatar Jul 08 '21 17:07 johanbrandhorst

Thanks for that. The PR is here: https://github.com/improbable-eng/grpc-web/pull/1023

bryanmcgrane avatar Jul 08 '21 21:07 bryanmcgrane