Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upwebsockets in grpcwebproxy #180
Conversation
JCGrant
added some commits
Apr 26, 2018
| ### Enabling Websocket Transport | ||
| By default, grpcwebproxy will not use websockets as a trasport layer. To enable |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
| @@ -34,6 +34,8 @@ var ( | ||
| runHttpServer = pflag.Bool("run_http_server", true, "whether to run HTTP server") | ||
| runTlsServer = pflag.Bool("run_tls_server", true, "whether to run TLS server") | ||
| useWebsockets = pflag.Bool("use_websockets", false, "whether to use beta websocket tranport layer") |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
| // gRPC-Web compatibility layer with CORS configured to accept on every | ||
| wrappedGrpc := grpcweb.WrapServer(grpcServer, grpcweb.WithCorsForRegisteredEndpointsOnly(false)) | ||
| options := []grpcweb.Option{ | ||
| // gRPC-Web compatibility layer with CORS configured to accept on every |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
JCGrant
added some commits
Apr 26, 2018
| @@ -49,8 +49,7 @@ $GOPATH/bin/grpcwebproxy | ||
| ### Enabling Websocket Transport | ||
| By default, grpcwebproxy will not use websockets as a trasport layer. To enable | ||
| websockets, set the `--use_websockets` flag to true | ||
| By default, grpcwebproxy will not use websockets as a transport layer. To enable websockets, set the `--use_websockets` flag to true |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
johanbrandhorst
Apr 26, 2018
Collaborator
I think a full stop at the end of this sentence would be correct as well.
johanbrandhorst
Apr 26, 2018
Collaborator
I think a full stop at the end of this sentence would be correct as well.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Thanks for the PR, looks good. Will test it tomorrow. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
timotheecour
commented
May 3, 2018
|
friendly ping on this |
easyCZ
approved these changes
May 8, 2018
LGTM, @MarcusLongmuir do you mind taking a look?
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
hope merged, thanks! |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
oops, websockets cannot work with Java backend (https is ok). |
alexpdp7
referenced this pull request
Jun 11, 2018
Closed
Provide complete bidirectional example if possible? #205
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bianbian-org
Jun 14, 2018
Contributor
@JCGrant need help please. May I ask what is your backend server based? I use a Java-based backend, ws could return Status Code: 101 Switching Protocols, but cannot handle any other requests and disconnect when timeout. ie. proxy always got rpc error: code = Canceled:
grpcwsproxy_1 | time="2018-06-14T14:39:48Z" level=info
msg="finished streaming call" error="rpc error: code = Canceled desc = context canceled"
grpc.code=Canceled grpc.method=GetXXX grpc.service=xxx.Service grpc.start_time="2018-06-14T14:38:48Z" grpc.time_ms=59971 span.kind=server system=grpc
|
@JCGrant need help please. May I ask what is your backend server based? I use a Java-based backend, ws could return Status Code: 101 Switching Protocols, but cannot handle any other requests and disconnect when timeout. ie. proxy always got rpc error: code = Canceled:
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
JCGrant
Jun 14, 2018
Contributor
@bianbian-org I use a Go backend. Unfortunately, I'm not entirely sure what is causing your issues.
|
@bianbian-org I use a Go backend. Unfortunately, I'm not entirely sure what is causing your issues. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bianbian-org
Jun 15, 2018
Contributor
Thanks all the same @JCGrant
I maybe found the problem, finally!
When using grpc-web-client with Websocket as transport, it depends on the finishSendFrame to tell the server that the client has finished sending:
enum WebsocketSignal {
FINISH_SEND = 1
}
const finishSendFrame = new Uint8Array([1]);
...
finishSend: () => {
if (!ws || ws.readyState === ws.CONNECTING) {
sendQueue.push(WebsocketSignal.FINISH_SEND);
} else {
sendToWebsocket(WebsocketSignal.FINISH_SEND);
}
},And in the grpc-web/websocket_wrapper, it waits the signal:
if len(framePayload) == 1 && framePayload[0] == 1 {
return 0, io.EOF
}However, when call grpc methods, it do not call the finishSend(). So the grpc-web-socket-proxy is always waiting for the finishSendFrame in request till timeout.
When add the finishSendFrame manually, it works!
|
Thanks all the same @JCGrant enum WebsocketSignal {
FINISH_SEND = 1
}
const finishSendFrame = new Uint8Array([1]);
...
finishSend: () => {
if (!ws || ws.readyState === ws.CONNECTING) {
sendQueue.push(WebsocketSignal.FINISH_SEND);
} else {
sendToWebsocket(WebsocketSignal.FINISH_SEND);
}
},And in the grpc-web/websocket_wrapper, it waits the signal: if len(framePayload) == 1 && framePayload[0] == 1 {
return 0, io.EOF
}However, when call grpc methods, it do not call the finishSend(). So the grpc-web-socket-proxy is always waiting for the finishSendFrame in request till timeout. When add the finishSendFrame manually, it works! |
bianbian-org
referenced this pull request
Jun 15, 2018
Merged
grpcClient.finishSend() is essential for websocket transport #211
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
alexpdp7
Jun 17, 2018
I've got this working with a Java gRPC server, sent a single request and got a response back correctly.
alexpdp7
commented
Jun 17, 2018
|
I've got this working with a Java gRPC server, sent a single request and got a response back correctly. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jcloutz
commented
Jul 11, 2018
|
This works with a C# backend as well, any chance it will be merged soon? |
JCGrant commentedApr 26, 2018
•
edited
I have used these changes in a project at my job, and they seem to work well!