Skip to content

Cannot catch Exception from Server Stub #141

@ryanhall07

Description

@ryanhall07

I am attempting to install a default Exception handler for our gRPC server stubs. I have tried using both a java gRPC interceptor and coroutine exception handlers, but nothing seems to work. The following code snippet below replicates the issue.

val handler = CoroutineExceptionHandler { _, ex ->
  println("this never happens!!")
}

internal class TestGreeterGrpcService : GreeterGrpcKt.GreeterCoroutineImplBase(handler) {
  override suspend fun sayHello(request: HelloRequest): HelloReply = throw RuntimeException("boom")
}

Using the debugger I traced the issue to here

https://github.com/grpc/grpc-kotlin/blob/master/stub/src/main/java/io/grpc/kotlin/ServerCalls.kt#L229

It seems like the CoroutineContext provided to the stub is not used in the Flow that dispatches requests.

I'm fairly new to coroutines so maybe I'm doing something wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions