Skip to content

Report failed HTTP requests in 00265 instead of dropping the evidence - #112112

Merged
PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-00265-report-failed-http-requests
Aug 7, 2026
Merged

PedroTadim merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-00265-report-failed-http-requests

Conversation

@groeneai

Copy link
Copy Markdown
Collaborator

Related: #111777

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):

...

Description

00265_http_content_type_format_timezone discards the evidence when one of its HTTP
requests fails, so a failed request is reported as a bare result differs with no error
text anywhere.

Every one of its 13 invocations has the shape

${CLICKHOUSE_CURL} -vsS "${CLICKHOUSE_URL}" ... 2>&1 | grep -e '< Content-Type' ... | sort

2>&1 merges curl's diagnostics into the pipe, grep drops them, and the pipeline's exit
status is grep/sort's rather than curl's. CLICKHOUSE_CURL carries no --fail
(tests/queries/shell_config.sh:156) and stateless .sh tests do not set -e. Measured
against a listener that accepts and then resets the connection, the current shape yields
pipeline_rc=0, empty stdout and zero bytes of stderr: the failure leaves no trace at
all, and the only symptom is that whole 3-line header groups are missing from the output.

Why that matters beyond cosmetics. tests/clickhouse-test already knows how to handle
these runs: process_result_impl checks if stderr: and returns FailureReason.STDERR
before the RESULT_DIFF branch, and MESSAGES_TO_RETRY already contains
(total) memory limit exceeded. Because the test deleted curl's stderr, the description
contains only a diff, so the existing retry machinery is blind to it. Of the three
occurrences of this failure recorded in the CI database over 30 days, the one that happened
to let the server's error text through was classified correctly and is retryable today,
while the two that swallowed it produced an unattributable result differs. Same trigger,
opposite outcomes, and the difference is entirely the discard.

What changed. A local curl_headers helper writes curl's -v diagnostics to a file and
pipes that file into the existing grep/sed/sort chains unchanged. When curl reports a
non-zero exit status, or when the response carries no X-ClickHouse-Timezone header (which
every request here must answer with), it reports curl's own diagnostic and the response body
on stderr instead of letting grep eat them. URLs, settings, filter chains and the
.reference file are untouched.

Both conditions are needed and neither subsumes the other, which is why the message names
both: a server that refuses the request before parsing answers 200-style with
curl exit 0 and no timezone header, while a connection reset gives a non-zero curl exit.
A response whose headers are complete but whose body is then truncated satisfies the header
condition and is caught by the exit status alone; that shape passes on master today and
becomes a loud failure here, which is intended: a request that did not complete should not
be reported as a success.

Three details are load-bearing and each is covered by a mutation test:

  • Classification is by the required response header, not by the exception code. One
    invocation deliberately runs a failing query (intDiv by zero) and the reference
    expects its X-ClickHouse-Timezone header, so keying on the exception code would
    redden every healthy run. The reference has exactly 13 X-ClickHouse-Timezone lines for
    13 invocations, so requiring that header is universal here. The match must stay anchored
    (^< X-ClickHouse-Timezone:), because the server lists that name in
    Access-Control-Expose-Headers on every response.
  • The response body goes to a file, never a shell variable. The test requests Native
    and RowBinary, whose bodies contain NUL; command substitution truncates at the NUL and
    makes bash print warning: command substitution: ignored null byte in input, which would
    itself fail the test.
  • Both files are truncated before each request. On an early transport failure curl never
    opens -o, so a previous request's body would otherwise be reported as belonging to this
    one. That is not cosmetic: (total) memory limit exceeded is a live MESSAGES_TO_RETRY
    entry, so a stale body could attribute a false cause.

Scope. Nine sibling stateless tests share the same "run curl verbosely, then grep the
response header lines" shape and are deliberately left out of this PR: each needs its own
error-path reasoning (some of their lines legitimately expect no match, one greps non-2xx
responses on purpose, and two count matches, so for those a silently empty response is a
false pass rather than a red, which is worse than the failure fixed here). The shared
CLICKHOUSE_CURL definition in tests/queries/shell_config.sh is also deliberately
untouched: 319 tests use it and several depend on reading error bodies, non-2xx responses,
or specific curl exit codes.

Verification. Healthy requests emit exactly zero bytes of stderr (12 consecutive runs),
the test's stdout is byte-identical to origin/master's output on the same binary
(sha256 7611820edd3674d2..., which is also the .reference hash), 50/50 randomized runs
pass, and six concurrent copies pass with no temporary-directory collisions. Reverting the
helper makes both real-world failure shapes silent again; dropping the header guard alone,
replacing the body file with command substitution, dropping the truncation, or leaving a
single invocation un-routed each re-break exactly one measured property.

groeneai and others added 2 commits July 27, 2026 09:41
Every one of the 13 invocations in 00265_http_content_type_format_timezone.sh
had the shape

    ${CLICKHOUSE_CURL} -vsS ... 2>&1 | grep -e '< Content-Type' ... | sort

`2>&1` merges curl's diagnostics into the pipe, `grep` drops them, and the
pipeline's exit status is `grep`/`sort`'s rather than curl's. `CLICKHOUSE_CURL`
carries no `--fail` and stateless `.sh` tests do not `set -e`, so a request that
never reached query execution produced missing header lines and nothing else:
measured against a listener that accepts and then resets the connection, the old
shape yields `pipeline_rc=0`, empty stdout and zero bytes of stderr.

That is not only cosmetic. `tests/clickhouse-test` already handles these runs:
`process_result_impl` checks `if stderr:` and returns `FailureReason.STDERR`
before the `RESULT_DIFF` branch, and `MESSAGES_TO_RETRY` already contains
`(total) memory limit exceeded`. With curl's stderr discarded the description
holds only a diff, so the existing machinery is blind to it. Of the three
occurrences recorded in the CI database over 30 days, the one that let the
server's error text through was classified correctly, while the two that
swallowed it produced an unattributable `result differs`.

Route every invocation through a local `curl_headers` helper that keeps curl's
`-v` diagnostics in a file, pipes that file into the unchanged
`grep`/`sed`/`sort` chains, and reports the diagnostic plus the response body on
stderr when the request never reached query execution. URLs, settings, filter
chains and the `.reference` file are untouched, and the test's stdout stays
byte-identical.

Three details are load-bearing, each covered by a mutation test:

  * Classification is by the required `X-ClickHouse-Timezone` response header,
    not by the exception code: one invocation deliberately runs a failing query
    and the reference expects its timezone header, so keying on the exception
    code would redden every healthy run. The match stays anchored because the
    server lists that name in `Access-Control-Expose-Headers` on every response.
  * The response body goes to a file: the test requests `Native` and
    `RowBinary`, whose bodies contain NUL, and command substitution both
    truncates at the NUL and makes bash warn on stderr.
  * Both files are truncated before each request: on an early transport failure
    curl never opens `-o`, so a previous request's body would otherwise be
    reported as belonging to this one, and `(total) memory limit exceeded` is a
    live `MESSAGES_TO_RETRY` entry, so a stale body could attribute a false
    cause.

The nine sibling stateless tests that share this shape are deliberately left
alone: each needs its own error-path reasoning, and two of them count matches,
so for those a silently empty response is a false pass rather than a red. The
shared `CLICKHOUSE_CURL` definition is also untouched, since 319 tests use it
and several depend on error bodies, non-2xx responses or specific curl exit
codes.

Co-Authored-By: Claude Opus 5 <[email protected]>
…adline

The guard added in the previous commit fires on a disjunction: a non-zero `curl`
exit, OR a response with no `X-ClickHouse-Timezone` header. Its message and the
comment above the helper described only the second condition, so the first one
printed a false statement.

Measured against a listener that emits complete, correct `200` headers including
a real `X-ClickHouse-Timezone`, then a `Content-Length` larger than the body it
actually sends, then a reset: `curl` exits 56 with the header present, so only
the exit-status condition fires, and the report claimed the request never
reached query execution when it demonstrably had. That shape is caught either
way; only the wording was wrong.

Reword the single unconditional `echo` to cover both conditions and keep
`(curl exit $rc)`, which is what discriminates a header-missing response from a
transport failure. Update the comment block to state both conditions. No logic
change: the guard, the truncation, the body file, the anchored match and all 13
call sites are untouched, and the test's stdout stays byte-identical to
`origin/master`'s (sha256 7611820edd3674d2..., which is also the `.reference`
hash).

The new headline was checked against `MESSAGES_TO_RETRY` in
`tests/clickhouse-test`: it matches none of the 11 entries, so it cannot itself
make a run retryable.

Related: ClickHouse#111777

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (2 rounds, click to expand)

This change was reviewed by an independent model before publication, then re-reviewed after
the fix round. Verdicts below; every claim was re-derived against origin/master.

Round 1 - 1 major, 1 nit (same defect), 1 major disagreed

❌ The failure headline described only one of the guard's two conditions. The guard fires on
a disjunction (curl exited non-zero, or the response carried no X-ClickHouse-Timezone),
but the message and the comment above the helper described only the second. Measured against a
listener that sends complete, correct 200 headers including a real X-ClickHouse-Timezone,
then a Content-Length larger than the body it actually sends, then a reset: curl exits 56
with the header present, so only the exit-status condition fires - and the report claimed the
request never reached query execution when it demonstrably had. Raised independently by the cold
review and by the gate, so it was not overridable. Fixed in the second commit: one reworded
unconditional echo plus a comment block naming both conditions. No logic change - the guard,
the truncation, the body file, the anchored match and all 13 call sites are byte-identical, and
the test's stdout stays equal to origin/master's.

⚠️ "Failure path is not demonstrated in both directions" - disagreed, with evidence. The
measurements requested already exist and were re-read from the raw logs: pre-fix
pipeline_rc=0, empty stdout, zero bytes of stderr on an accept-then-reset listener versus
post-fix 441 bytes and a non-zero helper status; reverting the helper reproduces the literal
< Content-Type: text/plain; charset=UTF-8 line seen in the CI report with no stderr; dropping
only the header condition silences the early-refusal shape (curl exit 0) while the reset shape
stays loud, so the two conditions are separately load-bearing; dropping the truncation
reintroduces a stale response body into the next request's report; replacing the body file with
command substitution makes bash warn on the Native body. The re-review did not raise it again.

Round 2 - clean

The re-review of the fix round returned no findings. The round was verified to be
comment-and-string-only by classifying every added and removed line (8 comment lines, 2 echo
lines, nothing else) and by hashing the file with comments stripped at three revisions - the
previous head and this head are identical apart from that one echo, with origin/master as a
live differing control. The three healthy response shapes are byte-for-byte identical at both
heads, and the two failure shapes differ by exactly the 10 bytes the new headline adds.

💡 Noted, not blocking. One comment line added by the first commit names curl and -o
without inline code formatting. The lines added by the fix round do format them; the measured
convention in comparable stateless shell tests is 11 formatted versus 61 not, and re-touching a
line this round does not otherwise edit would have broken the comment-only property that makes
the round cheap to verify.

Session id: cron:clickhouse-review-slot-10:20260727-133900

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, 100% and build-free. A local listener that accepts a connection then resets it (SO_LINGER {1,0}) driven through the test's exact pipeline shape gives pipeline_rc=0, stdout_len=0, 0 bytes of stderr on every run: the failed request leaves no trace. A second listener returning a 500 with X-ClickHouse-Exception-Code: 241 and no X-ClickHouse-Format/X-ClickHouse-Timezone reproduces the other observed shape (+< Content-Type: text/plain; charset=UTF-8 with the two other header lines gone) at curl exit 0.
b Root cause explained? Each of the 13 invocations is ${CLICKHOUSE_CURL} -vsS ... 2>&1 | grep -e '< Content-Type' ... | sort. 2>&1 merges curl's diagnostics into the pipe, grep drops them, and the pipeline's exit status is grep/sort's, never curl's; CLICKHOUSE_CURL carries no --fail (tests/queries/shell_config.sh:156) and stateless .sh tests do not set -e. So a request that never reached query execution produces missing header lines and nothing else. That matters because process_result_impl checks if stderr: and returns FailureReason.STDERR before the RESULT_DIFF branch, and MESSAGES_TO_RETRY already contains (total) memory limit exceeded. With the stderr discarded, the description holds only a diff, so the existing retry machinery cannot see it.
c Fix matches root cause? Yes: the fix is at the exact point of discard. curl_headers writes curl's -v diagnostics to a file, pipes that file into the unchanged grep/sed/sort chains, and reports curl's own diagnostic plus the response body on stderr whenever either condition holds: curl exited non-zero, or the response carried no X-ClickHouse-Timezone header. Neither subsumes the other, so the headline names both — HTTP request failed or did not reach query execution (curl exit $rc): — because the exit-status condition also fires on a request that demonstrably did reach query execution: a response with complete, correct headers (timezone header present) whose body is then truncated, measured at curl exit 56. No bound widened, no no-random-* tag, no dataset reduced, no product code touched, no assertion changed, .reference byte-identical.
d Test intent preserved / new tests added? Preserved and measured, not asserted: the test's stdout is byte-identical to origin/master's output on the same binary (sha256 7611820edd3674d2..., which is also the .reference hash). 13 invocations before and after; the reference's 13 X-ClickHouse-Timezone lines are unchanged. A healthy run emits exactly 0 bytes of stderr across 12 consecutive runs, so the added error path cannot redden a healthy run. No new test file: the deliverable is that an existing failure becomes visible, which is verified by the mutation matrix in (e).
e Both directions demonstrated? Yes, on the same accept-then-reset listener. Pre-fix (file verbatim from origin/master): pipeline_rc=0 stdout_len=0 stderr_bytes=0. Post-fix (helper extracted verbatim from the committed file): stderr_bytes=441, first line HTTP request failed or did not reach query execution (curl exit 56):, helper returns 1, and the remaining invocations still run (no set -e). Six-shape matrix, healthy vs failing, each under both grep filters the test uses: TSV / Native (NUL-bearing body) / the intentional intDiv-by-zero query all stay silent (0 bytes of stderr); the early-refusal (curl exit 0, no timezone header), connection-reset (curl exit 56, no header) and truncated-response (curl exit 56, header present) shapes are all loud, each printing the same single unconditional headline with the discriminating curl exit value. Reverting the helper makes every failure shape silent again while the three healthy shapes are unchanged.
f Fix is general across code paths? Yes within the file: all 13 invocations are routed, not just the one that failed in CI. A mutation that leaves a single invocation un-routed shows that line silent (stderr_bytes=0) while routed lines are loud, so a partial fix would leave 12 identical holes. Nine sibling stateless tests share the shape and are deliberately out of scope: each needs its own error-path reasoning, and two of them (04055_http_header_crlf_injection, 00372_cors_header) count matches, so for those a silently empty response is a false pass rather than a red and needs a behaviour decision. The shared CLICKHOUSE_CURL definition is deliberately untouched (319 consumers, several depend on error bodies, non-2xx responses or specific curl exit codes).
g Fix generalizes across inputs? Yes for the inputs this test spans: all 6 response formats it requests, including Native and RowBinary whose bodies contain NUL (hence the body file; with command substitution instead, the Native shape emits warning: command substitution: ignored null byte in input, measured), the URL-parameter and --data-binary request forms, and the deliberately failing query. Classification is by the required X-ClickHouse-Timezone response header rather than by the exception code, because that failing query legitimately returns one; dropping the header guard alone makes the early-refusal shape (curl exit 0) go silent while the reset shape stays loud, and conversely the exit-status condition is the only thing that catches a truncated response whose headers, timezone header included, arrived intact — so the two conditions are separately load-bearing and the headline names both. The match is anchored (^< X-ClickHouse-Timezone:) because the server lists that name in Access-Control-Expose-Headers on every response, which would otherwise invert the guard into a no-op.
h Backward compatible? N/A, test-only change. No settings, no SettingsChangesHistory.cpp, no serialization format, no product code (git diff -- src/ programs/ base/ is empty).
i Invariants and contracts preserved? The invariant is what reaches grep is unchanged: previously the merged stream, now the diagnostics file, which holds exactly the -v header lines with the body diverted to -o; since grep only ever matched < Header lines, the matched set is identical, pinned by the byte-identical-output hash in (d). The guard's own contract is that a complete, successful request is silent and anything else is reported once, on stderr, with a headline that is true for both ways it can fire — curl exiting non-zero, or the timezone header missing — checked against the truncated-response shape where only the first fires; the headline is also checked against the live MESSAGES_TO_RETRY list (11 entries parsed out of tests/clickhouse-test) so it cannot itself make a run retryable. Also preserved: the file still has no set -e, so a failed invocation lets the rest run and the diff still localises the break; the trap ... EXIT is the only trap in the file (origin/master has none) and removes the temporary directory on every exit path; mktemp -d under ${CLICKHOUSE_TMP} keeps it parallel-safe, verified with 6 concurrent copies all passing with 0 leftover directories, so no no-parallel tag is needed. Both files are truncated before each request because curl never opens -o on an early transport failure: without that, a stale body reappears in the next request's report, and since (total) memory limit exceeded is a live MESSAGES_TO_RETRY entry it would attribute a false cause (measured: stale text present on the mutant, absent with the truncation).

Session id: cron:clickhouse-impl-slot-46:20260727-123200

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @CheSema — could you review this? It is a test-only change: all 13 invocations in 00265_http_content_type_format_timezone.sh had the shape ${CLICKHOUSE_CURL} -vsS ... 2>&1 | grep '< Header', so a failed HTTP request lost curl's diagnostic to grep and surfaced as a bare result differs with no error text anywhere; the requests now keep those diagnostics in a file and report them on stderr when curl fails or the response carries no X-ClickHouse-Timezone, leaving the .reference byte-identical.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 27, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6acb367]

Summary: ❌

job_name test_name status info comment
Stress test (arm_asan_ubsan, s3) FAIL
UndefinedBehaviorSanitizer: undefined behavior (STID: 0250-4a9f) FAIL cidb IGNORED

AI Review

Summary

This PR rewrites tests/queries/0_stateless/00265_http_content_type_format_timezone.sh so the existing header checks still see the same successful output, while failed HTTP requests now preserve curl diagnostics on stderr instead of letting grep drop them. I reviewed the current diff, the full touched script, the existing PR discussion, and the current CI report, and I did not find a correctness or contract gap that warrants an inline finding on the current version.

Final Verdict

✅ No findings.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 27, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 6acb367

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stress test (arm_asan_ubsan, s3) / UndefinedBehaviorSanitizer: undefined behavior (STID 0250-4a9f) UBSan signed integer overflow at src/Functions/toStartOfInterval.cpp:293:80, bare origin + offset on the DateTime64 origin overload; trunk bug, 47 rows / 40 unrelated PRs / 5 master hits in 30d #112045 (external, open)

Not PR-caused: this PR's diff is src/Common/QueryFuzzer.cpp-free and touches only
tests/queries/0_stateless/00265_http_content_type_format_timezone.sh, which cannot reach
FunctionToStartOfInterval. The overflow is still present on origin/master (grep for the
addOverflow guard returns nothing there), so recurrence on any sanitizer job is expected until
#112045 merges.

Session id: cron:our-pr-ci-monitor:20260728-023000

@PedroTadim PedroTadim self-assigned this Aug 7, 2026
@PedroTadim
PedroTadim added this pull request to the merge queue Aug 7, 2026
Merged via the queue into ClickHouse:master with commit 1856d0a Aug 7, 2026
177 of 179 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors 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.

4 participants