Skip to content

It should be _easy_ to detect when a stream ends #2438

@MatthiasvB

Description

@MatthiasvB

Feature Request

Simply put, when I have stream, I may need to do cleanup when it is closed. Everything else is a memory leak.

There are multiple issues that discuss this, most notably #377

The solution proposed in the referenced issue is far from trivial. I don't consider replacing low level details related to future impls a sufficient solution for a library at the level of tonic. While I will be forced to get down to that level in my app, I am fairly certain that the API this should be providing is one of an enum, say

enum StreamEvent<T, E> {
  Message(T),
  ClientDisconnect,
  // the following is more of a guess
  Error(E),
}

This feels quite natural to me, and so I wonder why it isn't already done this (or a similar) way. Are there technical difficulties to detect connection termination? Any other "hard" reason? Or was this just never tackled?

Motivation

It is of utmost relevance to clean up resources that are not needed anymore

Proposal

See above

Alternatives

One could track connections via IDs and have a separate event that tells us which ones have terminated, but I feel that would increase complexity

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