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:
<code>@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.
});
}
</code>
<code>@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.
});
}
</code>
@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?