Detect client disconnection with `body::Sender`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.3k
- Forks
- 1.8k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 14
Description
Describe the solution you'd like
I'm using hyper::body::Sender to send an SSE stream to the client. For each connection there is an associated Tokio task that subscribes to a distributed message queue, and I would like to stop the task on client disconnection. It seems that currently there isn't a method on Sender that allows to detect disconnection without attempting to send a message.
I think an API like this would work:
impl Sender {
pub async fn wait_disconnect(&mut self) -> Result<()>;
}
Describe alternatives you've considered
- Send heartbeat messages to the client periodically and stop the task on failure.
- Periodically call
poll_ready.
I'm already doing 1 anyway, but this adds latency between the client closing the connection and the server stopping the task, even when the connection is gracefully shut down.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the implementation of hyper::body::Sender and reviewing how send and poll_ready currently report client disconnection. Assess the proposed wait_disconnect API and its interaction with SSE tasks; done means a reviewed API design with behavior and coverage for graceful client shutdown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend, networking
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100