Skip to content

Recognize a broken HTTP stream when fetching Native blobs in test 04819 - #116370

Merged
alexey-milovidov merged 4 commits into
masterfrom
fix-04819-poisoned-native-blob
Aug 30, 2026
Merged

alexey-milovidov merged 4 commits into
masterfrom
fix-04819-poisoned-native-blob

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

Related: #116341
Related: #116342
Related: #112052

Issue #116341 was meanwhile closed by #116342, which deflaked the same fetches with a fetch_native_blob helper that greps the blob for DB::Exception and sleeps between retries. This PR replaces that helper with the stricter curl exit-code check described below (per the suggestion in the issue): only the deliberate mid-stream break (curl exit code 18) is retried, any other failure aborts the test immediately, and the shared-variant fetch that #116342 left raw is guarded too.

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

...

Test 04819_dynamic_aggregate_function_state_version fetches Native blobs over HTTP with curl and pipes them into INSERT ... FORMAT Native, without checking whether the producing query actually succeeded. When a transient error (a parallel-replicas coordinator/replica teardown race, ATTEMPT_TO_READ_AFTER_EOF → UNKNOWN_CODEC) fires after the server has already sent the 200 header, the exception text lands in the blob file, and the test fails far away from the real cause with a misleading Unknown type code: 0x61 (INCORRECT_DATA).

The server already breaks the HTTP protocol on purpose in this case - the terminating empty chunk is never sent (a fixed-length response is cut short the same way) - so curl recognizes the poisoned stream and exits with an error (18, transfer closed with outstanding read data remaining), as suggested in #116341 (comment). The test now fetches every blob through a fetch_blob helper that checks the curl exit code (with --fail covering an error that comes before the first byte) and retries the transient failure up to 10 times; if the fetch keeps failing, the last curl error is printed and fails the test with the real reason.

Verified locally against a server with the stateless-test configuration and parallel replicas enabled by default (default_parallel_replicas over 3 loopback replicas): the test passes repeatedly with and without randomized settings, a mid-stream failure (throwIf after the first blocks) makes curl exit with code 18 and the helper retries and then reports it, and a pre-stream failure is caught by --fail with exit code 22.

The underlying transient (ATTEMPT_TO_READ_AFTER_EOF in receivePartitionMergeTreeReadTaskResponse and the UNKNOWN_CODEC protocol desync on the initiator) is not addressed here and may deserve its own investigation, as noted in the issue.


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

Version info

  • Merged into: 26.9.1.370 (included in 26.9 and later)

The server breaks the HTTP protocol on purpose when a query fails after
streaming has started - the terminating chunk is never sent - so `curl`
exits with an error instead of passing the poisoned stream off as a
result. Fetch every Native blob through a helper that checks this (and
`--fail` for a failure before the first byte) and retries, so a
transient parallel-replicas teardown race cannot feed exception text
into `INSERT ... FORMAT Native` and fail the test with a misleading
`Unknown type code` error.

#116341 (comment)

Co-Authored-By: Claude Fable 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3932617]

Summary: ✅


AI Review

Summary

This PR replaces the ad-hoc blob validation in 04819_dynamic_aggregate_function_state_version.sh with a curl-status-based fetch helper so the test retries the deliberate mid-stream HTTP break and stops earlier on other fetch failures. That is directionally right, but one remaining diagnostic gap still hides the original server exception on pre-stream HTTP failures, so I would not approve the PR yet.

Findings

⚠️ Majors

  • [tests/queries/0_stateless/04819_dynamic_aggregate_function_state_version.sh:52] fetch_blob now uses curl --fail, which drops the HTTP response body on a pre-stream 500. In that path the helper reports only curl: (22) The requested URL returned error: 500, so the CI fix still loses the actual DB::Exception text for failures that happen before the first response byte.
    Suggested fix: preserve and print the response body on the non-18 path as well, for example with --fail-with-body plus emitting the saved body when status == 22.
Final Verdict
  • Status: ⚠️ Request changes
  • Preserve the server exception body for non-18 HTTP failures so the test reports the actual ClickHouse error instead of only a generic curl status.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 25, 2026
alexey-milovidov and others added 3 commits August 27, 2026 19:40
…her failure

Address review: the retry loop in `fetch_blob` masked every non-zero
`curl` exit, and the harness runs `.sh` tests without `errexit`, so the
final `return 1` let the test keep running on a partial blob. Now only
the deliberate mid-stream break (`curl` exit code 18, the transient from
issue #116341) is retried; any other failure, or an exhausted retry,
aborts the test immediately with the last `curl` error.

#116370

Co-Authored-By: Claude Fable 5 <[email protected]>
Conflict in `04819_dynamic_aggregate_function_state_version.sh`: master
merged #116342, which deflaked the same fetches with a
`fetch_native_blob` helper that greps the blob for `DB::Exception` and
sleeps between retries. Resolved in favor of this PR's `fetch_blob`
(the `curl` exit-code check suggested in issue #116341), removing the
now-dead `fetch_native_blob`; this PR also guards the shared-variant
fetch that #116342 left raw.

Co-Authored-By: Claude Fable 5 <[email protected]>
local url="$1" fetch_query="$2" out="$3" error status=0
for _ in {1..10}
do
error=$($CLICKHOUSE_CURL --fail -sS "$url" --data-binary "$fetch_query" 2>&1 > "$out") && return 0

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.

The new helper only captures curl's stderr. With --fail, an HTTP 500 before the first response byte now collapses to curl: (22) The requested URL returned error: 500 and discards the server's DB::Exception body, so this CI fix still hides the real cause for pre-stream failures. Can we preserve the response body on the non-18 path as well (for example via --fail-with-body plus printing the saved body when status == 22)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No problem with that.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

LGTM

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

Labels

pr-ci pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants