Thomas Cesare-Herriau
09/29/2022, 10:40 PMgrpc-kotlin
wrapper to grpc-java
already supports setting Deadlines on Client Stubs (using the withDeadline function), however there is no "Kotlin coroutine" equivalent to the io.grpc.Context#withDeadline function that allows wrapping any operation into a Cancellable context with a deadline (a deadline that is then propagated to all gRPC client stubs within the operation!).
The problem is that the io.grpc.Context#withDeadline
API requires using a ScheduledExecutorService
, which as I understand it, would require bypassing Kotlin coroutine architecture. An alternative is to use `withTimeout`: however this results in 2 separate contextual timeouts (the withTimeout
one and a potential propagated gRPC Deadline in the context)
Has anyone here had to set server-side deadlines/timeouts in the past (in the context of gRPC servers)? If so, what approach have you used?enleur
09/30/2022, 10:52 AMScheduledExecutorService
override fun <ReqT, RespT> interceptCall(
call: ServerCall<ReqT, RespT>,
headers: Metadata,
next: ServerCallHandler<ReqT, RespT>,
): ServerCall.Listener<ReqT> {
return Contexts.interceptCall(Context.current().withDeadline(), call, headers, next)
}
Thomas Cesare-Herriau
09/30/2022, 4:06 PMContext.current().withDeadline()
require passing the scheduler though? The signature of withDeadline
API requires it. Or am I missing something? Looking at the io.grpc.Context
code, the deadline
attribute is only set on the Context.CancellableContext
which is created thru withDeadline