Detect streaming client disconnects
@wllenyj ci sta già lavorando.
Dal 4/8/2023.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Description of problem
The async server does not detect if a client disconnects ungracefully from a streaming API. For example, let's say a client wishes to subscribe to updates streamed from the server. The connection is established, and the server starts streaming updates to the client. If the client dies, the server does not immediately realize this and continues to send events.
For example, adapting the async-stream-server file to only read the first message from the client, then echo back an increasing sequence number forever:
async fn echo_stream(
&self,
_ctx: &::ttrpc::r#async::TtrpcContext,
mut s: ::ttrpc::r#async::ServerStream<streaming::EchoPayload, streaming::EchoPayload>,
) -> ::ttrpc::Result<()> {
let mut e = s.recv().await?.unwrap();
loop {
e.seq += 1;
println!("Sleep 1 second to simulate waiting for an event");
sleep(std::time::Duration::from_secs(1)).await;
println!("sending: {}", e.seq);
let result = s.send(&e).await;
if result.is_err() {
println!("error sending item!");
}
}
}
With this client implementation:
async fn echo_stream(cli: streaming_ttrpc::StreamingClient) {
let mut stream = cli.echo_stream(default_ctx()).await.unwrap();
let echo = streaming::EchoPayload {
seq: 0,
msg: "Echo in a stream".to_string(),
..Default::default()
};
stream.send(&echo).await.unwrap();
while let Ok(resp) = stream.recv().await {
println!("{}", resp);
}
}
Expected result
I'm not sure what would be best; some options are:
- Cancel the async future the service method is executing in (like non-streaming async does if the client dies)
- Provide some kind of token that can be selected on (like #180)
- Propagate the write error back to the service method (so errors can be detected when calling
s.send(&e).await;). While I think this makes sense to do regardless, it's a lot more convenient if the client disconnect can be detected before trying to send something to it.
Actual result
Client output:
seq: 5 msg: "Echo in a stream"
seq: 6 msg: "Echo in a stream"
^C <-- client killed
Server output:
... snip ....
Sleep 1 second to simulate waiting for an event
sending: 6
Sleep 1 second to simulate waiting for an event
sending: 7
Sleep 1 second to simulate waiting for an event
[00:00:19.969] (7ffb7073b640) ERROR write_message got error: Socket("Broken pipe (os error 32)")
sending: 8
Sleep 1 second to simulate waiting for an event
[00:00:20.970] (7ffb7073b640) ERROR write_message got error: Socket("Broken pipe (os error 32)")
- Lingua principale
- Rust
- Stelle
- 374
- Fork
- 64
- Merge medio
- 3g 5h
- PR unite (30g)
- 6
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di containerd/ttrpc-rust
-
Async server reorders and drops client-stream DATA framesForse già presa @shvbsle l’ha presa 19 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 15/100
containerd/ttrpc-rust#340 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
containerd/ttrpc-rust#338 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
containerd/ttrpc-rust#317 · 1 commento ·
-
Add single connection support to ServerForse già presa @KarstenB l’ha presa 204 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
containerd/ttrpc-rust#293 ·
-
Can the asynchronous client connect operation support asynchronous mode to avoid connect blocking?Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
containerd/ttrpc-rust#265 · 1 commento ·
Tutte le issue di containerd/ttrpc-rust
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
longbridge/nsh#4201 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
moq-dev/moq#10463 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno