How can I check if client terminated the gRPC connection?

32 Views Asked by At

In Nestjs, I am creating a gRPC bidirectional stream connection between the server and client.

Here is what I understand. A gRPC stream is using HTTP/2, which will start a single TCP connection and multiplex multiple streams over it. When the stream is closed, the TCP connection is still open and can be reused for future requests.

Based on the docs, My gRPC server will be implemented like this:

@GrpcStreamCall('StreamService', 'openStream')
async openStream(requestStream: ServerDuplexStream<Message, Message>) {
        requestStream.on('close', async () => {
            // This event is emitted when the stream is closed. Not when the TCP connection is closed.
        });
}

Since the close event is emitted when the stream is closed. Not when the TCP connection is closed/terminated. I want a way to detect/handle if the client terminated the TCP connection from the server-side How?

1

There are 1 best solutions below

0
murgatroid99 On

You can't. gRPC does not expose connection information to the server application.