async client: request timeout does not cover outbound queue and socket write
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- rust
- Ambito
- backend-api-design, networking, performance
Direzione di ricerca
Inizia da src/asynchronous/client.rs e src/asynchronous/connection.rs, seguendo Client::request, i percorsi di streaming e il canale writer bounded descritto nell’issue. Verifica i corrispondenti percorsi di risposta del server asincrono e di shutdown, quindi confronta src/sync/client.rs e src/sync/channel.rs per il comportamento sync correlato. Il lavoro è completo quando le deadlines coprono l’ammissione, le scritture e le attese delle risposte; il lavoro scaduto non viene inviato; le registrazioni vengono ripulite; le scritture bloccate non possono affamare gli altri chiamanti; e la copertura di regressione esercita la cancellazione e i peer bloccati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
The async ttrpc client can remain blocked beyond Request.timeout_nano when the connection writer stops making progress.
Client::request registers the stream and waits to enqueue the message before starting the timeout:
self.streams.lock()?.insert(stream_id, tx);
self.req_tx
.send(SendingMessage::new(msg))
.await?;
let result = tokio::time::timeout(
Duration::from_nanos(timeout_nano as u64),
rx.recv(),
)
.await?;
Relevant source:
All messages for a connection are serialized through one writer task and a bounded mpsc channel with a capacity of 100. The writer calls GenMessage::write_to, whose write_all/flush operations have no deadline.
If the peer remains connected but stops reading:
- The writer task blocks in
write_to. - The writer stops draining the outbound channel.
- The 100 outbound queue slots fill.
- Later
Client::requestcalls block inreq_tx.send(...).await. - Their
timeout_nanois never started because execution has not reachedtokio::time::timeout. - These calls can therefore remain pending indefinitely.
This is connection-wide head-of-line blocking: one blocked socket write prevents unrelated RPCs from being submitted.
Timed-out requests also leak stream registrations
The client inserts the stream into self.streams before queue admission. There is no cleanup guard covering all early-return and cancellation paths.
If:
- queue admission is canceled externally;
- response waiting times out; or
- the request future is dropped;
the corresponding entry can remain in self.streams until a response arrives or the complete connection disconnects.
A successfully enqueued request that times out also remains in the outbound queue. If the writer later recovers, the expired request may still be transmitted after its caller has returned.
Expected behavior
A non-zero Request.timeout_nano should bound the complete client-side request lifecycle:
stream registration
-> outbound queue admission
-> socket write
-> response wait
Specifically:
- Waiting for outbound queue capacity must honor the request deadline.
- A queued request that expires before being written must be discarded.
- A request must not be transmitted after its deadline if no bytes were written.
- Cancellation during a possibly partial frame write must close or poison the connection.
- Every timeout, cancellation, send failure, and dropped future must remove its stream registration.
- Other callers must not remain indefinitely blocked behind an expired request.
Actual behavior
The timeout only wraps rx.recv() after queue admission. It does not cover:
- waiting for space in the outbound channel;
- the actual socket write;
- streaming sends;
- stream initialization; or
- cleanup of
self.streams.
Streaming paths
The same writer is used by streaming operations.
new_stream waits for req_tx.send(...).await without applying Request.timeout_nano. StreamSender::send and close_send wait for both queue admission and the writer result without a request deadline.
These paths should be included in the fix and regression coverage.
Async server behavior
The async server uses the same Connection writer task and another bounded 100-message channel.
The per-request timeout wraps the service handler, but sending the response happens afterward. If the writer is blocked and its response queue fills, completed handler tasks can remain blocked while enqueueing responses even though the request timeout has expired.
The server response and shutdown paths should therefore also be audited for the same transport invariant.
Sync client behavior
The sync client has a related manifestation:
- It uses one sender thread for all requests.
write_messageperforms blocking writes without a deadline.- Requests are submitted through an unbounded
std::sync::mpscchannel. recv_timeoutlets individual callers return, but it does not cancel their queued or in-progress messages.- Continued calls can grow the outbound queue without bound while the sender thread remains blocked.
Relevant source:
The async implementation is the primary subject of this issue, but the sync implementation should either be fixed together or tracked separately.
Impact
A peer that remains connected but stops reading can cause:
- all unrelated RPCs on that connection to be starved;
- async request futures to outlive their configured timeout;
- unbounded growth of the sync outbound queue;
- accumulation of stale stream-map entries;
- expired requests to be transmitted later;
- streaming operations to hang indefinitely; and
- connection shutdown to wait on blocked response tasks.
This is particularly harmful when lifecycle/control RPCs and diagnostic traffic share one long-lived ttrpc connection.
- 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 ·
-
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 ·
-
Please update `protobuf` to the latest v3.5.1 version for both ttrpc-codegen and ttrpc-compilerAperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 42/100
containerd/ttrpc-rust#237 ·
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