Skip to content

How to launch fire-and-forget server-streaming RPC inside RPC #476

@rygx

Description

@rygx

I was trying to implement a cascade gRPC (say gRPC service A and gRPC service B), where service A launches B and immediately returns, and B is a server-streaming call.

My problem is that the service B is not successfully executed. Not sure if it was cancelled silently.

Inside service A (gRPC unary call), I implemented like below:

// inside service A
val threadLocalContext = Context.current().fork()
threadLocalContext.run {
  CoroutineScope(GrpcContextElement(threadLocalContext)).launch{
    // intends to call service B here but not successful. Seems nothing happens.
    val result = serviceBStub.invokeServerStreamingService(serviceBRequest)
  }
}

// service A exits

But it turns out that the service B server streaming call was never invoked. If I change B to a unary call it can successfully execute. So it seems that thread local is propagated, but I am not sure if this is the case in server streaming call situation.

Or if the server streaming call was cancelled? I did not see any exceptions being thrown.

Can someone tell me what went wrong and how to make it behave as intended? Thanks!

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