grpc / grpc-web

gRPC for Web Clients
https://grpc.io
Apache License 2.0
8.45k stars 761 forks source link

net::ERR_CONNECTION_RESET 200 (OK) #1341

Open DAIMENGEN opened 1 year ago

DAIMENGEN commented 1 year ago

I'm now in a situation like this: Client: grpc-web, typescript Server: akka-stream, akka-grpc, akka-http, scala

premise: The client sends a request to the server through ClientReadableStream, and the server returns a stream.

need: I want to close the server now, and eventually kill the server process, so I executed the System.exit(1) method.

The specific execution steps are as follows First: close the active stream (KillSwitches.shared("service-switch").shutdown()) Second: close akka-http (ServerBinding.terminate) Third: Close the ActorSystem (ActorSystem.terminate()) Fourth: Close the process (System.exit)

But in the browser I occasionally get the following error http://xxxxxx/xxxxx/getStream net::ERR_CONNECTION_RESET 200 (OK)

Client, this is how I listen to the stream

`

    const stream_result =  client.getFSStationResultStream(request,{token: 'XYZ'})
    stream_result.on('end', () => {
        console.log('stream_result end')
        stream_result.removeListener('end')
    })

`

However, I found that stream_result.on('end',...) fires twice every time the process is killed. In most cases, two times are normal, and occasionally there will be an error, Please see the information below.

In most cases, the browser's console print information is like this stream_result end stream_result end

Occasionally this happens: stream_result end index.js:42 POST http://10.20.243.23:50052/proto.web.FusiaWebService/getFSStationResultStream net::ERR_CONNECTION_RESET 200 (OK)

Can anyone help to analyze the cause of the problem?

DAIMENGEN commented 1 year ago

Sorry, the problem description is wrong. The end event doesn't fire twice, it fires once, sometimes it succeeds, sometimes it fails