Repository navigation
[adapters] Close a connection when the client closes it - #7966
Conversation
A client that disconnects from a streaming response that writes nothing, such as /coordination/status while the status does not change, leaked the connection and the stream's state. Actix kept the half-closed connection open until a write failed. The pipeline's HTTP server now closes the connection when it reads EOF from the client. Because a disconnect now cancels the handler, Controller::rebalance requests the step from the command callback instead of after it awaits the reply.
| // Close the connection when the client closes it. Otherwise a streaming response that | ||
| // writes nothing, such as `/coordination/status` while the status does not change, | ||
| // leaks its connection until a write fails. | ||
| .h1_allow_half_closed(false) |
There was a problem hiding this comment.
pitfall (medium): This applies to every handler, not only streaming responses. I tested it with a real HttpServer. A client sent POST with a full body and then called shutdown(SHUT_WR), which HTTP/1.1 allows. It received 0 bytes, and the handler future was dropped at its next .await. For the pipeline, that means:
/input_endpointwhile paused: the request is cancelled instatus_watch.changed(), so its data is never ingested, and no error is logged./approve,clock_advance, and similar handlers are cancelled partway.
The manager's clients (reqwest/awc) don't half-close, so this is probably fine in practice. Please note the trade-off in this comment. Also please audit for other send-command → await → side-effect handlers like the old rebalance. I found none besides rebalance, but new ones will need the same pattern from now on.
|
What I ran:
missing (high) – feldera-pr-checks gate #2 (unit tests) fails: This changes behaviour and adds no test. The let mut sock = TcpStream::connect(addr).await?;
sock.write_all(b"GET /coordination/status HTTP/1.1\r\nHost: x\r\n\r\n").await?;
// read the response headers and the first status chunk, then:
sock.shutdown().await?;
timeout(Duration::from_secs(10), async { while sock.read(&mut buf).await? > 0 {} }).await.expect("server closed the connection");missing (medium): Nothing tests the |
Stacked on #7963, which bumps actix-web to 4.12.
Issue
A client that disconnects from a streaming response that writes nothing (for example
/coordination/status,/coordination/step/status,/coordination/checkpoint/statuswhile the value does not change) leaks the connection and the stream's state. Actix keeps the half-closed connection open until a write fails.Fix
The pipeline's HTTP server sets
h1_allow_half_closed(false), so it closes the connection when it reads EOF from the client. A disconnect now cancels the handler, soController::rebalancerequests the step from the command callback instead of after it awaits the reply.