Skip to content

http/client: handle early server response during streaming body write#3410

Open
levenon wants to merge 1 commit into
scylladb:masterfrom
levenon:master
Open

http/client: handle early server response during streaming body write#3410
levenon wants to merge 1 commit into
scylladb:masterfrom
levenon:master

Conversation

@levenon

@levenon levenon commented May 19, 2026

Copy link
Copy Markdown

When using body_writer for streaming uploads (e.g., chunked transfer), the server may send an error response and close the connection before the client finishes writing the body. Previously, do_make_request() serialized write_body and recv_reply, meaning the client could not detect the server's early response until write_body completed — which may never happen for long-lived streams, as writes continue to succeed into kernel/userspace buffers even after the remote end has closed.

Fix this by running write_body and recv_reply concurrently via when_all(). If recv_reply completes first (server responded early), shutdown_output() is called to immediately abort the in-progress write. If write_body completes first (normal flow), recv_reply proceeds as before without shutdown.

This resolves a hang where streaming HTTP clients would remain stuck in write_body indefinitely after the server had already rejected the request.

When using body_writer for streaming uploads (e.g., chunked transfer),
the server may send an error response and close the connection before
the client finishes writing the body. Previously, do_make_request()
serialized write_body and recv_reply, meaning the client could not
detect the server's early response until write_body completed — which
may never happen for long-lived streams, as writes continue to succeed
into kernel/userspace buffers even after the remote end has closed.

Fix this by running write_body and recv_reply concurrently via
when_all(). If recv_reply completes first (server responded early),
shutdown_output() is called to immediately abort the in-progress write.
If write_body completes first (normal flow), recv_reply proceeds as
before without shutdown.

This resolves a hang where streaming HTTP clients would remain stuck
in write_body indefinitely after the server had already rejected the
request.
Comment thread src/http/client.cc
return _write_buf.flush().then([this] {
return recv_reply();

return do_with(false, [this, &req](bool& write_done) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For short bodies (those without body writer function set) this can be avoided

Comment thread src/http/client.cc
}
return make_ready_future<reply_ptr>(std::move(rep));
})
).then([](auto joined) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fit for .then_unpack() sugar

@xemul

xemul commented May 29, 2026

Copy link
Copy Markdown
Contributor

Test that reproduces the issue is needed badly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants