Consulting about zio-grpc bi-stream closing invoke: When it will be closed? I'm use grpcurl to test bistream, but zio-grpc server side not close immidently(it will closed after some time).
I'm watching grpc server-side stream close event by Stream.ensuring
. For detail:
- for request stream: consume request stream in a fiber by forkDomaen: I'm suppose the grpc request stream will be closed if the stream closed.
request
.mapM { reqItem =>
// do action here
UIO(println(s"test get some data from request item: ${reqItem}"))
}
.runDrain
.catchAll(error => ZIO(println(s"find some error: $error")))
.ensuring {
UIO(println(s"request stream closed"))
}
.forkDaemon
- for server-side response stream: I'm suppose the grpc response stream will be closed if I'm close the created response Stream instance.
ZStream.fromEffect {
Queue.unbounded[String].flatMap { queue =>
ZStream.fromQueue(queue)
}
}.flatten
.ensuring {UIO(println("response stream closed"))}
The code works well to handle request and response , besides, it will invoke some other business logic in ensuring
but ignored here for simplify.
Questions:
- Is't the best practice to handle bi-stream closed action by
ZStream.ensuring
with zio-grpc? - Is't by design on zio-grpc to lantancy close the stream even though client-side close the stream? In this situation is grpcurl closed by Ctrl-C which I have noticed the underlaying TCP is closed normally by check FIN req-rsp. Thanks.