Skip to content

Give the native handshake in test_default_session_user a deadline that covers a slow reject - #120753

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-native-hello-handshake-deadline
Sep 19, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-native-hello-handshake-deadline

Conversation

@groeneai

@groeneai groeneai commented Sep 18, 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):

Give the response read of the hand-rolled native Hello helper in the test_default_session_user integration test a 60s deadline, so that a rejected login is still observed on a coverage-instrumented server.

Description

test_default_session_user/test.py::test_native_default_session_user_with_password fails only on Integration tests (amd_llvm_coverage, N/8), with TimeoutError: timed out at native_hello's sock.recv(1): 3 failures over 7,621 coverage rows in 30 days, on three unrelated PRs (one documentation-only), and 0 master failures in 90 days.

Root cause: a rejected native login is answered only after two symbolized stack traces are rendered, in AccessControl::authenticate's catch and inside writeException, which flushes the packet afterwards. In the failing job's log those renders took 8.59s and 10.35s: the first response byte arrived 18.9s after connect.

This gives only that read 60s, installed after the Hello is sent, so connection establishment keeps its 10s deadline and an unreachable listener still fails fast. 60000ms is what this repo already uses for a handshake read deadline on a slow lane, in five places: 00563_shard_insert_into_remote.sql (by Alexey Milovidov) and four earlier CI fixes of mine (01600, 02040, 03630, 03443).

The client's own handshake_timeout_ms default is also 10s, but that is a failover SLA, not a bound on observing a rejection. A hung server still fails at 60s, inside the 900s pytest cap.

Validation: against a stub answering after 15s the failure reproduces: pre-change TimeoutError at sock.recv(1) in 10s, the exact CI frame; post-change the Exception packet at 15s. Against a saturated accept queue, connect still gives up in 10.01s. 18.9s is a CI measurement; on an idle box the same binary rejects in 0.1s.

Deliberately unchanged, none with a timeout failure in 90 days: postgres_login and the web-terminal socket in this file (one render each, not the two that gate a native reject), test_interserver_marker_requires_cluster_secret (rethrown before sendException, so no render gates a packet) and test_tcp_hello_string_limits (a client timeout is part of its oracle).

CI provenance: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=115680&sha=4ee5eff0aca01d92279bfa3fc109a743eefbf9a1&name_0=PR&name_1=Integration%20tests%20%28amd_llvm_coverage%2C%202%2F8%29


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

Version info

  • Merged into: 26.10.1.153 (included in 26.10 and later)

…t covers a slow reject

test_native_default_session_user_with_password fails only on the
amd_llvm_coverage integration shards, with "TimeoutError: timed out" at
native_hello's sock.recv(1): 3 failures over 7,621 coverage rows in 30 days,
across three unrelated PRs (one of them documentation-only), and 0 master
failures in 90 days.

A rejected native login is answered only after two symbolized stack traces are
rendered. The first comes from the catch in AccessControl::authenticate
(src/Access/AccessControl.cpp:629); the second from writeException
(src/IO/WriteHelpers.cpp:77-85), reached through TCPHandler::runImpl's
sendException (src/Server/TCPHandler.cpp:507, :531) with the server context's
calculate_text_stack_trace, and the packet reaches the wire only after it. Since
StackTrace::toStringCached keys on the exact frame-pointer triple, the two
distinct exceptions each pay a full DWARF symbolization. In the failing job's
log (PR ClickHouse#115680 / 4ee5eff, coverage 2/8) those renders took 8.59s and
10.35s, so the client's first byte arrived 18.9s after connect; a second case in
the same run took 16.6s. The helper allowed 10s.

Nothing here is a server defect: coverage binaries are never shipped, the same
renders cost 0.04s once the DWARF is parsed, and the logging is deliberate
(AccessControl.cpp:661-663). The server's handshake_timeout_milliseconds is
checked only before a read (src/IO/ReadBufferFromPocoSocket.cpp:106), which is
why the answer does arrive at 18.9s instead of the connection being dropped.

60s is not an arbitrary pick: 60000ms is the value this repository already uses
for a handshake read deadline on a slow lane, in six places. One is
00563_shard_insert_into_remote.sql (SET handshake_timeout_ms = 60000, by Alexey
Milovidov, d4fed63); four are my own merged CI fixes (01600, 02040, 03630,
03443), each commented that the default 10s handshake_timeout_ms is not enough on
slow lanes; stress_tests.lib:362 uses 30s. Two samples fix the order of magnitude
of a first-time symbolization on a loaded runner, not its tail, so a deadline
just above the observed maximum would re-flake. The cost is bounded: this is a
deadline rather than a sleep, so a passing call pays nothing, native_hello has no
retry loop, and pytest.ini's timeout = 900 still catches a genuine hang.

The client's own handshake_timeout_ms default is also 10s, but that setting is an
SLA for a real connection deciding when to fail over. This read only observes
whether a login was rejected and asserts nothing about latency, so a
client-realistic deadline adds no assertion value and only decides how often the
observation is lost.

Alternatives rejected: suppressing either render removes deliberate diagnostics
on a security-relevant path; calculate_text_stack_trace=0 in the test profile
would leave render ClickHouse#1 at 8.59s, i.e. 86% of a 10s budget, and weaken diagnostics
for the module's other tests; skipping the case under coverage deletes reject-path
coverage on the flavour whose purpose is measuring it.

Two other hand-rolled native Hello sites are deliberately left alone.
test_interserver_marker_requires_cluster_secret rethrows in interserver mode at
TCPHandler.cpp:521-526 before sendException, so the packet-gating render is
structurally absent and its oracle is a closed connection; it has never failed
with this signature. In test_tcp_hello_string_limits a client timeout is part of
the oracle (a rejection arm returns False on socket.timeout), and that module
shortens the server's handshake timeout to 3000ms on purpose.

Validation: with the coverage binary from the failing job the module passes 30/30
and the three native_hello callers pass 10 times each. The failure is reproduced
deterministically against a stub listener answering after 15s: before this change
the helper raises TimeoutError at sock.recv(1) in 10.01s, the exact CI frame;
after it, the helper returns the Exception packet at 15.00s. A never-answering
stub fails at 10s before and 60.00s after, so the constant is the operative
variable, and an arm answering ServerHello instead still reddens the assertion in
0.05s. The 18.9s magnitude is measured in CI and is not reproducible on an idle
box, where the same binary answers a reject in 0.105s.

Co-Authored-By: Claude Opus 5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Sep 18, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings; it read the full changed
module, every native_hello caller, both hand-rolled native-Hello sibling modules and the server
exception paths), plus my own cold read of the resulting diff before seeing the implementation notes.
Three nits, no blocker and no major; two of them were fixed in this description before publication.

# Sev Finding Verdict Evidence / action
1 💡 The description named only the two other-file hand-rolled Hello siblings left unchanged, not the two in this same file AGREE, fixed it now names postgres_login and the web-terminal socket, with the reason: one render each, not the two that gate a native reject, and no timeout failure in 90 days
2 💡 The description said 60000ms appears "in six places", while five sites use 60000 and stress_tests.lib uses 30000 AGREE, fixed corrected to five
3 💡 The new comment says "the default 10s handshake timeout", but the bound it replaced was this helper's own literal: handshake_timeout_ms is installed only in Connection.cpp, and the server's handshake_timeout_milliseconds is checked before a read AGREE, not blocking the wording mirrors the merged comments in 01600, 02040, 03443 and 03630, where that setting is the operative bound; recorded here rather than churning a 6-line diff

Also considered and rejected: tagging the case out of the coverage flavour, which is the remedy the
stateless sibling 04078_native_protocol_input_validation got in 36decd61da30d. It does not
transfer. The stateless suite has a job that re-runs its skipped tests with an uninstrumented binary;
the integration suite has neither that tag nor such a job, so skipping here would delete the
reject-path coverage instead of moving it.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal
per finding.

Session id: cron:clickhouse-review-slot-49:20260918-073800

@clickhouse-gh

clickhouse-gh Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [53225ee]

Summary: ✅


AI Review

Summary

This PR narrows the timeout change in native_hello to the post-Hello response read: connect still fails after 10 seconds, while the first response byte may wait up to 60 seconds for the slow coverage-instrumented reject path. That matches the flaky scenario described in the PR without broadening the earlier failure mode I was concerned about, and I did not find any remaining correctness or test-behavior issues in the current head.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Sep 18, 2026
@groeneai
groeneai requested a review from tavplubix September 18, 2026 08:19
socket.create_connection(address, timeout=T) installs T on the socket before
connect and leaves it installed, so widening it for the slow reject response
also widened connection establishment for all 14 native_hello assertions in
this module: a blackholed port would then burn 60s per call instead of 10s
before the real failure becomes visible. Every observed occurrence of this
flaky failure timed out in recv(1), never in create_connection, so only the
response read needs the wider deadline.

Measured with native_hello loaded from the test file itself, against a stub
whose response latency is controlled and against a port whose accept queue is
saturated so its SYNs are dropped. Before: a blackholed connect raised
TimeoutError after 60.06s, and the live socket reported connect/recv deadlines
of 60.0/60.0. After: 10.01s, and 10.0/60.0 with settimeout(60) observed before
recv. Unchanged by this commit: a 15s-delayed reject still returns the
exception packet at 15.00s, an immediate wrong answer still fails in 0.00s, and
a server that never answers still fails at 60.06s, 15x inside the 900s
pytest-timeout cap.
@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Sep 18, 2026
@alexey-milovidov alexey-milovidov self-assigned this Sep 19, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 19, 2026
Merged via the queue into ClickHouse:master with commit e73a84a Sep 19, 2026
176 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 Sep 19, 2026
@clickhouse-gh clickhouse-gh Bot added comp-authentication Identity verification: users, credentials, auth methods, external auth providers. and removed comp-testing Test content only (no production code). labels Nov 22, 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 comp-authentication Identity verification: users, credentials, auth methods, external auth providers. groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding 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.

3 participants