Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a Sink argument instead of returning a Stream for response streaming #1656

Open
chebbyChefNEQ opened this issue Mar 13, 2024 · 0 comments

Comments

@chebbyChefNEQ
Copy link

chebbyChefNEQ commented Mar 13, 2024

Feature Request

Love the project! Just one request on response streaming.

Most (because I haven't used all of them) gRPC implementation passes a sink/writer handle into the handler stub. In the stub implementation, users may call sink.send(response) or write.write(response) to stream data to the client. However, tonic makes the handler return a Resonse<RPCStream> type.

This has two issues

  1. This usually leaks tokio::spawn handles; or that user needs to build special apparatus to keep track of these handles.
  2. We exit Layers before stream is completed

Crates

I think just tonic?

Motivation

  1. stream back from inside the handler, instead of a stray tokio task
  2. able to have more control over streaming response in Layers. -- concurrent stream limits, response coalescing, etc.

Proposal

TBD

Alternatives

  • maybe tonic runtime can take a join handle in the handler return value and wait for the task to finish before exiting the layers? Less powerful then Sink interface but solves the control issue in Layer
@chebbyChefNEQ chebbyChefNEQ changed the title Use a Sinkargument instead of returning a Stream Use a Sink argument instead of returning a Stream for response streaming Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant