hyperium / hyperium/hyper

Detect client disconnection with `body::Sender`

Open
#2,917 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature
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

  1. Send heartbeat messages to the client periodically and stop the task on failure.
  2. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.