Skip to content

Fix flaky test 02865_tcp_proxy_query_packet_validation - #107056

Merged
CheSema merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-02865-tcp-proxy-query-packet-validation
Jun 11, 2026
Merged

CheSema merged 1 commit into
ClickHouse:masterfrom
groeneai:fix-flaky-02865-tcp-proxy-query-packet-validation

Conversation

@groeneai

@groeneai groeneai commented Jun 10, 2026 •

Copy link
Copy Markdown
Collaborator

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

Fixes a rare flaky failure of 02865_tcp_proxy_query_packet_validation, reported by @ alexey-milovidov on #106222 ("return code: 1" while the expected output was otherwise produced; 104/104 re-runs with the same randomized settings passed). The failure is unrelated to that PR.

Root cause: the test sends malformed Hello packets to the proxy TCP port and expects the server to reject them. When validate_tcp_client_information is on (set in the CI test config), the server rejects the malformed Query packet during parsing, before a query context exists. Per TCPHandler.cpp it sends the exception and then closes the connection, because it consumed only part of the packet and the trailing client bytes would be misinterpreted as the next packet. The client (printf) has already written those trailing bytes, which the server never reads, so the close produces a TCP RST. The RST can race ahead of nc reading the buffered exception, so a single attempt occasionally yields no output, and the last grep then exits 1 with the expected line missing.

Fix: wrap each probe in a bounded retry loop that re-sends until the expected rejection message appears. A genuine breakage still fails, because every attempt yields empty output and the diff against the reference does not match. The reference file and the assertions are unchanged; the fix is in the test only.

Version info

  • Merged into: 26.6.1.648

The test sends malformed Hello packets to the proxy TCP port and expects
the server to reject them with "client_name does not match" and
"version does not match".

When validate_tcp_client_information is on (set in the CI test config),
the server rejects the malformed Query packet during parsing, before a
query context exists. Per TCPHandler.cpp it sends the exception and then
closes the connection, because it consumed only part of the packet and
the trailing client bytes would be misinterpreted as the next packet.
The client (printf) has already written those trailing bytes, which the
server never reads, so the close produces a TCP RST. The RST can race
ahead of nc reading the buffered exception, so a single attempt
occasionally yields no output. With no pipefail/set -e in the test, the
script exit code is then the last grep's exit (1, no match) and the
expected line is missing, which is exactly the observed CI failure
("return code: 1" with the expected output otherwise produced; 104/104
re-runs with the same randomized settings passed).

Wrap each probe in a bounded retry loop that re-sends until the expected
rejection message appears. A genuine breakage still fails: every attempt
yields empty output and the diff against the reference does not match.
The reference file and the assertions are unchanged.

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

Copy link
Copy Markdown
Collaborator Author

Pre-PR validation gate

# Question Answer
a Deterministic repro? Yes. Started a local server with validate_tcp_client_information=true (the CI test setting; default is false) and the proxy TCP port enabled. The original test fails on demand when the server's error response is lost to the post-rejection close: simulated with a stub nc that yields empty output on the first attempts, the original single-attempt test exits 1 with no output, exactly the CIDB signature ("return code: 1", expected line missing).
b Root cause explained? The server rejects the malformed Hello during Query-packet parsing (no query context yet), sends the exception, then closes the connection because it consumed only part of the packet (TCPHandler.cpp). The client already wrote trailing bytes the server never reads, so the close emits a TCP RST that can race ahead of nc reading the buffered exception. nc then yields no output; with no pipefail/set -e, the script exit becomes the last grep's exit (1, no match) and the expected line is missing.
c Fix matches root cause? Yes. The lost response is a transient at the socket layer, so each probe is retried until the expected rejection message appears. No assertion is weakened, no setting is pinned, no set +e/pipefail trick is used.
d Test intent preserved / new tests added? Preserved. The reference file and the two asserted rejection messages are unchanged. When the rejection genuinely never appears (validation broken/removed), every attempt stays empty and the diff against the reference still fails — verified locally. The retry only absorbs the transient lost-response, never a real regression.
e Both directions demonstrated? Yes. Under a simulated transient (first attempts lose the response): original test → empty output, exit 1 (fail); new test → both reference lines, exit 0 (pass). Against the real server: 50/50 runs pass. Under permanent loss (genuine breakage): new test still fails the diff.
f Fix is general, not a narrow patch? This is a test-only flaky fix, not a code bug. The server's defensive close on a partial packet is correct and intentional. Sibling tests 01601_proxy_protocol and 03918_ssh_protocol use the same `printf

Session id: cron:clickhouse-worker-slot-2:20260610-184028

@groeneai groeneai mentioned this pull request Jun 10, 2026
1 task done
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @CheSema — could you review this test-only fix? It makes 02865_tcp_proxy_query_packet_validation retry each malformed-Hello probe, because the server's defensive close after rejecting the packet emits a TCP RST that can race ahead of nc reading the buffered exception, occasionally losing the expected output (rare flake; assertions and reference unchanged).

@PedroTadim PedroTadim added the can be tested Allows running workflows for external contributors label Jun 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [765e3e5]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_asan_ubsan, db disk, distributed plan, sequential) FAIL
03531_check_count_for_parquet ERROR cidb
Server died FAIL cidb
Segmentation fault (STID: 1367-2528) FAIL cidb
Stateless tests (arm_asan_ubsan, azure, sequential) FAIL
03531_check_count_for_parquet ERROR cidb
Server died FAIL cidb
Segmentation fault (STID: None) FAIL cidb

AI Review

Summary

This PR keeps 02865_tcp_proxy_query_packet_validation's two existing protocol rejection assertions, but retries each malformed Hello probe to absorb the documented socket-level lost-response race. The retry helper preserves the expected output/reference contract, the PR metadata matches a test-only CI fix, and I found no issues that need inline review comments.

Missing context / blind spots
  • ⚠️ PR CI was still pending at review time (PR and Fast test checks had not produced results); passing those checks would close this gap.
Final Verdict

Status: ✅ Approve

Pending CI should still complete before merge.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.60% 84.70% +0.10%
Functions 92.30% 92.30% +0.00%
Branches 77.20% 77.30% +0.10%

Changed lines: No C/C++ source files changed — skipping uncovered code analysis.

Newly covered by added/modified tests: 644 line(s), 53 function(s) across 147 file(s) · Details

Top files
  • src/Server/ACME/API.cpp: 61 line(s), 6 function(s)
  • src/Common/OpenSSLHelpers.cpp: 41 line(s), 1 function(s)
  • src/Server/ACME/Client.cpp: 39 line(s), 1 function(s)
  • src/Functions/FunctionShowCertificate.cpp: 38 line(s), 4 function(s)
  • src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp: 30 line(s)

Full report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI fully finished (Finish Workflow passed). Failures, both pre-existing chronic classes, none PR-caused (this PR fixes flaky 02865_tcp_proxy_query_packet_validation):

@CheSema
CheSema added this pull request to the merge queue Jun 11, 2026
Merged via the queue into ClickHouse:master with commit 381eea2 Jun 11, 2026
163 of 166 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 11, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Jun 17, 2026
…ted queries) and ClickHouse#107056

The prior CI run executed on a merge-base ~980 commits behind these fixes,
so it inherited the master-wide ASan heap corruption from ClickHouse#106020 (segfaults
during String serialization in DistributedSink / MergeTask / MergeMutate,
STIDs 1288-3bd5, 2046-50c3, 0988-1d81) plus the known-flaky
02865_tcp_proxy_query_packet_validation. Both are fixed on current master.
No conflicts; CREATE OR REPLACE size-check changes are unaffected.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ted queries) and ClickHouse#107056

The prior CI run executed on a merge-base ~980 commits behind these fixes,
so it inherited the master-wide ASan heap corruption from ClickHouse#106020 (segfaults
during String serialization in DistributedSink / MergeTask / MergeMutate,
STIDs 1288-3bd5, 2046-50c3, 0988-1d81) plus the known-flaky
02865_tcp_proxy_query_packet_validation. Both are fixed on current master.
No conflicts; CREATE OR REPLACE size-check changes are unaffected.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
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