Hi all! tl;dr: Has anyone here ever needed to crea...
# grpc
t
Hi all! tl;dr: Has anyone here ever needed to create server-side deadlines? _Background_: The
grpc-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?
e
in interceptors you can avoid messing with
ScheduledExecutorService
Copy code
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)
    }
t
Thanks @enleur for the. suggestion! Won't
Context.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