Skip to content

Watch the connection for an early response while sending an HTTP request body - #131102

Draft
CheSema wants to merge 16 commits into
socket-send-receive-nowfrom
http-watch-response-plain-tcp
Draft

CheSema wants to merge 16 commits into
socket-send-receive-nowfrom
http-watch-response-plain-tcp

Conversation

@CheSema

@CheSema CheSema commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Related: #131084
Related: #124326
Related: #124557

Step 5 of #131084. Stacked on #132376, the socket primitives for plain TCP, TLS and Silk fiber sockets.

Tests: gtest_http_early_response.cpp for a plain and a TLS server (an error stops the body; an answer before the reset that fails the send; a reset without an answer; header limits during the body), the body on Silk fiber sockets, and the integration rows of #131333.

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

While it sends the body of an HTTP request, ClickHouse now watches the connection for an early response, over HTTP and HTTPS. An error that the server sends before it reads the whole body, such as NoSuchUpload for an expired multipart upload, is now reported for every HTTP client (S3, Azure, the url engine and others), and not retried as a network error.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/131102]

… TCP

The body is sent with non-blocking writes while the connection is watched
for a response. An error status stops the body. TLS and Silk fiber
sockets keep the blocking send. The plain-HTTP read of
#124557 is removed.

Related: #131084
@clickhouse-gh

clickhouse-gh Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [477b125]

Summary: ❌

job_name test_name status info comment
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/can_be_merged.py --review-threads FAIL

AI Review

Summary

This PR watches for early HTTP responses during non-blocking plain TCP body writes, while retaining blocking writes for TLS and Silk sockets. ❌ Block: the existing finding still holds at head 477b1251ec60fd07e62b0e5798096f7c3dfe6754: a server error can arrive after the final readiness check and still be reported as a retryable network error.

Findings

❌ Blockers

  • src/IO/HTTP/HTTPClientIO.cpp:248 — A failed write still discards an already-arrived response. ready_to_send can return true, then the peer can send a complete 404 and reset the connection before the send. HTTPSession::writeRawNonBlocking stores and rethrows the send exception, and writeBody lets it escape without checking for the response. With the previous S3 recovery removed, this reaches PocoHTTPClient as NETWORK_CONNECTION, causing retries instead of reporting NoSuchUpload. A deterministic loopback TCP reproduction using the current production writeRawNonBlocking body confirmed that the final check returns 0, the write throws Connection reset by peer, and the complete 404 remains readable afterward. Handle a pending error response after a failed plain TCP write in the common writer; preserve the original send exception when no response is available. The existing unresolved thread already covers this finding, so no duplicate inline comment was posted.
Tests
  • ⚠️ Add a deterministic regression test that delivers the response and reset after the final ready_to_send check and before the send. AnswerWhileTheSendWaits delivers them inside the data hook, before that check, and therefore misses this window. Assert that the response is returned and the connection remains ineligible for reuse; retain coverage that a failed write without a response propagates its exception.
  • ⚠️ Local evidence is a focused reproduction with real TCP and the extracted production method body; hooks, throttling, exception storage, and the socket wrapper use minimal scaffolding. The full ClickHouse writer and S3 path were traced in source but were not executed locally. A regression test through the production transport would close that coverage gap.
Final Verdict

❌ Block. Handle the response arriving between the final check and a failed send, and add deterministic regression coverage. No additional new inline findings.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Nov 12, 2026
@CheSema
CheSema changed the base branch from master to http-response-parser November 12, 2026 18:32
Comment thread src/IO/HTTP/HTTPClientIO.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... label Nov 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing c21332e92 with master 53a98df12 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

59 object files changed (+24.05 KiB total), 2 added.

Object file Master PR Δ
base/poco/Net/CMakeFiles/_poco_net.dir/src/HTTPResponseParser.cpp.o new 44.15 KiB +44.15 KiB
src/CMakeFiles/clickhouse_common_io.dir/IO/ScopedNonBlocking.cpp.o new 16.37 KiB +16.37 KiB
base/poco/NetSSL_OpenSSL/CMakeFiles/_poco_net_ssl.dir/src/SecureStreamSocket.cpp.o 65.67 KiB 49.67 KiB -16.00 KiB (-24.36%)

711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.62, programs/clickhouse-keeper ×0.71 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.3 s 7.6 s +5.5 s (+265%)
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 5.8 s 8.6 s +5.0 s (+139%)
Compile time of recompiled translation units

417 translation units recompiled, 2811 s compile time in total, 415 of them have a recent master baseline.

Job report

Base automatically changed from http-response-parser to master November 13, 2026 11:34
…-plain-tcp

# Conflicts:
#	src/Common/Silk/tests/gtest_silk_fiber_stream_socket.cpp
#	src/IO/SocketPeerClosed.cpp
Blargian pushed a commit to Blargian/ClickHouse that referenced this pull request Nov 16, 2026
The tests-only part of ClickHouse#131102, unchanged: the `lingering` mode of
`NoSuchUploadAction` in the S3 mock, the early-error rows of
`test_early_error_response_at_upload_is_not_retried`, and the
`SilkFiberSocketTest.HTTPRequestBody` gtest. They pass on master, where
plain HTTP is handled by the read of ClickHouse#124557.

Related: ClickHouse#131084

Co-authored-by: Sema Checherinda <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
huldarchen pushed a commit to huldarchen/ClickHouse that referenced this pull request Nov 16, 2026
`ScopedNonBlocking` moves from an anonymous namespace in
`src/IO/SocketPeerClosed.cpp` to `src/IO/ScopedNonBlocking.{h,cpp}`, so
that other code in `src/IO` can use it, and the includes that only it
needed are removed from `SocketPeerClosed.cpp`. The code is taken
unchanged from ClickHouse#131102.
No behavior change.

Related: ClickHouse#131084

Co-authored-by: Sema Checherinda <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@CheSema
CheSema changed the base branch from master to socket-send-receive-now November 17, 2026 15:22
Step 5 of #131084. The body writer has one loop over `waitForSendOrReceive`, `sendNow` and `receiveNow` for plain TCP, TLS and Silk fiber sockets. After a failed send it reads what arrived, so an error response before a reset is not lost (#131102 (comment)). `ready_to_send`, `HTTPSession::writeRawNonBlocking` and `SocketImpl::throttleSendBlocking` are removed.
@CheSema CheSema changed the title Watch the connection for an early response while sending an HTTP request body on plain TCP Watch the connection for an early response while sending an HTTP request body Nov 17, 2026
@clickhouse-gh clickhouse-gh Bot added comp-networking The connection layer under the protocols, on the server and on the client side: socket read / wri... and removed comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... labels Nov 19, 2026

This branch has not been deployed

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

Labels

comp-networking The connection layer under the protocols, on the server and on the client side: socket read / wri... pr-improvement Pull request with some product improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant