grpc-web
grpc-web copied to clipboard
handle websocket closed event
https://github.com/improbable-eng/grpc-web/issues/543
Changes
on go/grpcweb
Change the error returned by webSocketWrappedReader.Read when the frame is a single byte of value 1 (which indicates the client has finished sending) from io.EOF to nil.
Rationale:
When a stream request is made using a websocket, handleWebSocket (wrapper.go) is called. This function run server.ServeHTTP to proxy the stream. Aside of forwarding messages from the server to the client, it reads messages coming from the websocket using the webSocketWrappedReader.Read method (websocket_wrapper.go), but this method was returning an io.EOF error when a end-of-message frame was received.
The fact is that the grpc.Server reads on the websocket until an error is returned by the read.
So when the wrapper was reading the end of the first message received by the client (the initial stream request), it was returning EOF and the grpc.ServerHTTP reader routine was stopped.
Then nobody was reading on the websocket after the first message was sent from the client, so when the closed event was sent from the frontend on a refresh or tab closed i.e, it could not detect it and close the entire stream.
Verification
I tested with my project which open infinite streams and I runned the go test, but more test could be done.
As discussed in the issue, this seems to break Chrome and Firefox tests.
https://travis-ci.org/improbable-eng/grpc-web/jobs/621194781?utm_medium=notification&utm_source=github_status
Is the CONTRIBUTING.md out of date ? I followed the whole instruction, and when I run npm test in src/github.com/improbable-eng/grpc-web it does almost nothing.
> grpc-web-ci@ test /home/felix/Projects/grpc-web/src/github.com/improbable-eng/grpc-web
> lerna run test
lerna notice cli v3.18.3
lerna info versioning independent
lerna info Executing command in 1 package: "npm run test"
lerna info run Ran npm script 'test' in '@improbable-eng/grpc-web-fake-transport' in 3.3s:
> @improbable-eng/[email protected] test /home/felix/Projects/grpc-web/src/github.com/improbable-eng/grpc-web/client/grpc-web-fake-transport
> jest
lerna success run Ran npm script 'test' in 1 package in 3.3s:
lerna success - @improbable-eng/grpc-web-fake-transport
So I'm not able to reproduce the CI output
Looks like it, unfortunately. You can follow the travis CI script to see what really happens in CI.
Hiya, this issue bit me today when trying to debug a client hanging after a call to close(). Anything I can do to help get this fix in?
Hiya, this issue bit me today when trying to debug a client hanging after a call to close(). Anything I can do to help get this fix in?
Hi! Please feel free to submit another PR with a fix, since this one seems to have stalled a bit.