Skip to content

Fix misleading Code 210 and opaque failures in functional-test server setup - #108593

Merged
Algunenano merged 8 commits into
ClickHouse:masterfrom
groeneai:fix-start-clickhouse-server-setup-flush-noise
Jul 1, 2026
Merged

Algunenano merged 8 commits into
ClickHouse:masterfrom
groeneai:fix-start-clickhouse-server-setup-flush-noise

Conversation

@groeneai

@groeneai groeneai commented Jun 26, 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

De-noise and de-opaque the "Start ClickHouse Server" functional-test setup stage. Two independent issues in ci/jobs/scripts/clickhouse_proc.py / ci/jobs/functional_tests.py:

1. Misleading Code: 210 ... Connection refused flush noise (correctness).
ClickHouseProc.start() ended with self._flush_system_logs(). Callers run wait_ready() after start() (e.g. functional_tests.py: CH.start() then CH.wait_ready()), so at that point the server has already written its pid file but is not yet listening on the TCP port. The pid file is written ~700 ms before the listener binds, so clickhouse-client --query "system flush logs" fails with Code: 210. DB::NetException: Connection refused (localhost:9000). (NETWORK_ERROR). The return value was discarded, so it never failed the job, but it polluted every setup log and made triage look like a startup crash.

The flush itself is kept: it pre-creates the system log tables (system.query_log, etc.), which are otherwise not materialized until the first flush, so individual tests can read them without hitting a "table does not exist" error. It is simply moved to where the server is actually ready and listening: into wait_ready()'s success path (the point at which the server has answered select 1). This keeps the table pre-creation while avoiding the Code 210 race against the TCP listener. The now-redundant explicit flush in start_light() is removed (it already calls wait_ready() first); terminate() keeps its end-of-job flush. The adjacent save_system_metadata_files_from_remote_database_disk() is kept (it uses the offline clickhouse disks tool, not a server connection).

Verified with a live debug server: firing system flush logs the instant the pid file appears returns Code: 210 (the old start() placement); firing it after select 1 succeeds (rc=0) and EXISTS TABLE system.query_log goes from 0 (before) to 1 (after), confirming the post-wait_ready flush still pre-creates the system log tables.

2. Opaque setup failures (observability).
When setup failed, the failing sub-step and the minio mc admin service restart status were only printed to stdout and never reached the persisted Result.info (CIDB test_context_raw), so unrelated sub-causes (server-not-ready, minio restart, kafka bring-up, stateful-data prep) all collapsed into one opaque "Cannot start clickhouse-server" bucket. This restructures the setup closure to print a concise SETUP FAILURE: <sub-step> marker at each failure point (from_commands_run captures the closure's stdout into Result.info on failure). For the non-fatal minio log-table/restart failure, create_minio_log_tables() now carries the concrete reason (the real clickminio restart status string) out via self.minio_setup_error, and the setup persists that concrete detail into the step Result.info via set_info even on the success path (it is otherwise only a report-page warning, invisible in CIDB). The bugfix-validation rebuild path's environment-setup error row is likewise annotated with the concrete sub-step that failed. Control flow is unchanged: minio remains non-fatal; stateful prep is still gated on has_stateful_tests.

Version info

  • Merged into: 26.7.1.358 (included in 26.7 and later)

The "Start ClickHouse Server" setup stage of functional/stress/upgrade
jobs intermittently logged a misleading
"Code: 210 ... Connection refused (localhost:9000) (NETWORK_ERROR)"
and collapsed unrelated setup sub-failures into one opaque bucket.

1) ClickHouseProc.start() flushed system logs before the caller runs
   wait_ready(): the server has written its pid file but is not yet
   listening on the TCP port (pid file is written ~700ms before the
   listener binds), so "system flush logs" fails with Code 210. The
   result was discarded, so it never failed the job, but it polluted
   every setup log and made triage look like a startup crash. Remove
   it: the flush is a startup no-op (no tests have run), and the
   meaningful flushes remain in terminate() and start_light() (which
   flushes after its own wait_ready()). The offline
   save_system_metadata_files_from_remote_database_disk() is kept.

2) Setup failures and the minio restart status were only printed to
   stdout, never surfaced into the persisted Result (CIDB
   test_context_raw). Print a concise "SETUP FAILURE: <sub-step>"
   marker at each failure point (from_commands_run captures the
   closure's stdout into Result.info on failure), and persist the
   non-fatal minio log-table/restart failure via set_info even on the
   success path. Control flow is unchanged.

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

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Launching the server and firing system flush logs the instant the pid file appears returns Code: 210 ... Connection refused (NETWORK_ERROR) on every attempt during the ~700 ms window between pid-file write and TCP-listener bind, then rc=0 once Ready for connections. Server log shows pid written at T+0.692s, TCP listening at T+1.365s.
b Root cause explained? Yes. ClickHouseProc.start() called _flush_system_logs(), but callers run wait_ready() after start(). The server writes its pid file ~700 ms before it binds the TCP port, so start()'s pid-poll succeeds and the flush runs while nothing is listening, producing Code 210. The return value was discarded, so it never failed the job, only polluted setup logs. Separately, setup sub-failures + minio restart status were only printed, never persisted into Result.info (CIDB test_context_raw), collapsing distinct sub-causes into one opaque bucket.
c Fix matches root cause? Yes. (1) Remove the premature flush from start() only; it is a startup no-op (no tests have run) and the meaningful flushes remain in terminate() and start_light() (post-wait_ready). (2) Print SETUP FAILURE: <sub-step> markers (captured into Result.info on failure) and persist the non-fatal minio failure via set_info even on success. No band-aids, no timeout bumps, no retries.
d Test intent preserved / new tests added? Yes. No test assertions are weakened. save_system_metadata_files_from_remote_database_disk() (offline clickhouse disks) is kept. Control flow is unchanged: minio remains non-fatal; stateful prep still gated on has_stateful_tests. This is a CI-harness observability/correctness change; verified via the real praktika Result class (failure markers captured on failure; minio note persisted on success).
e Both directions demonstrated? Yes. Without fix: 5/5 flush attempts in the bind gap return Code: 210. With fix: start() no longer runs the flush (AST-verified: present in start_light/terminate, absent in start); the post-ready flush still returns rc=0. Fix (2): Result.info contains SETUP FAILURE: ... on failure and the minio SETUP WARNING: ... on the success path.
f Fix is general across code paths? Yes. Verified every ClickHouseProc.start() caller (functional_tests.py, fast_test.py, fuzzers_job.py, sqllogic_test.py, sqltest_job.py) calls wait_ready() separately afterward, so none relied on the start() flush. performance_tests.py uses a different class (CHServer). The flush had been added (Oct 2025) to both start() (the bug) and start_light() (correct, post-wait_ready); only the buggy one is removed.
g Fix generalizes across inputs? N/A (CI-harness Python control-flow/observability change, not a datatype/engine code path).
h Backward compatible? N/A (CI-internal harness; no settings, on-disk/wire formats, or user-facing behavior changed).
i Invariants and contracts preserved? Yes. Setup control flow and fail-fast semantics are unchanged (minio still non-fatal, all other sub-steps still fatal); wait_ready()/metadata-save contracts untouched. set_info is the existing append API; Result.info to test_context_raw mapping is unchanged.

Session id: cron:clickhouse-worker-slot-6:20260626-102900

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @maxknv @leshikus — could you review this CI setup fix? It (1) removes a premature system flush logs in ClickHouseProc.start() that runs before the caller's wait_ready(), so it fires while the server has a pid file but no TCP listener yet and logs a misleading Code: 210 Connection refused on every functional/stress/upgrade setup (result discarded, kept in terminate()/start_light()); and (2) surfaces the failing setup sub-step and the minio restart status into the persisted Result (CIDB test_context_raw) so the opaque "Cannot start clickhouse-server" umbrella splits into measurable sub-causes. Control flow unchanged.

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

clickhouse-gh Bot commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [98b6015]

Summary: ✅


AI Review

Summary

This PR moves the startup system flush logs from ClickHouseProc.start into wait_ready, preserves the system-log-table pre-creation after the server is actually listening, and threads concrete MinIO/stateful setup failures into persisted Result.info for functional-test triage. I checked the current code, the full PR diff, the existing review threads and replies, and the helper behavior in Result.from_commands_run and Shell; I did not find any remaining correctness or regression issues in the touched paths.

Final Verdict

✅ No new findings on the current PR head.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jun 26, 2026
Comment thread ci/jobs/functional_tests.py Resolved
@Algunenano Algunenano self-assigned this Jun 26, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — fabd03f

CI fully finished (Finish Workflow + Mergeable Check passed). All functional/integration/build/style checks green; no test-level failures on this commit. Every red check below has an owner.

Check / test Reason Owner / fixing PR
CH Inc sync private fork-sync mirror CH Inc sync (private, not actionable by us)

Session id: cron:our-pr-ci-monitor:20260626-180000

@Algunenano

Copy link
Copy Markdown
Member

The flush is also pointless at startup (no tests have run yet)

@groeneai This is not true. At least historically (not sure if that's still the case) log tables were not created until something was flushed, so if a test tried to access system.query_log for example before anything had written to it it would get an error about the table not existing. By flushing we make sure the tables always exists so individual tests don't have to deal with it.

Please make sure you maintain the call to flush logs but do it after the server is ready and listening to queries.

Addresses review feedback on the FT server-bring-up cleanup.

The system-log flush is preserved (it pre-creates the system log tables, e.g.
system.query_log, so individual tests can read them without a "table does not
exist" error), but it now runs inside wait_ready() on the success path, i.e.
once the server is ready and listening. The previous flush in start() ran while
the server had written its pid file but had not yet bound the TCP port, so it
raced the listener and logged a misleading Code 210 (Connection refused). The
flush in start_light() is removed as redundant (it already calls wait_ready()
first); terminate() keeps its end-of-job flush.

create_minio_log_tables() now stores the concrete failure detail (the real
clickminio restart status string) on self.minio_setup_error, and the functional
test setup persists that concrete detail into the step Result.info (CIDB
test_context_raw) instead of a generic "see status above" note, so a broken
minio restart is queryable in CIDB even though it is non-fatal.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Jun 29, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

@Algunenano You're right, thanks for the correction. The flush is now kept and moved to after the server is ready and listening, not removed.

Done in 50d901f:

  • The flush moved into ClickHouseProc.wait_ready()'s success path (runs only after the server answers select 1). This preserves the system-log-table pre-creation (system.query_log etc.) while avoiding the Code 210 race against the TCP listener. The functional-test caller pattern CH.start() then CH.wait_ready() is covered, and so is fast_test (same pattern). start_light()'s explicit flush is removed as redundant (it already calls wait_ready() first); terminate() keeps its flush.
  • Verified on a live debug server: EXISTS TABLE system.query_log is 0 before the post-wait_ready flush and 1 after, confirming the table pre-creation still happens.
  • PR description reasoning corrected accordingly.

Also addressed the bot's inline note on the minio path: create_minio_log_tables() now carries the real clickminio restart status string out via self.minio_setup_error, and the setup appends that concrete detail with set_info (instead of the generic "see status above" note), so it lands in test_context_raw.

Comment thread ci/jobs/scripts/clickhouse_proc.py Resolved
groeneai and others added 2 commits June 29, 2026 11:12
create_minio_log_tables() is non-fatal: the functional-test setup keeps
going when it returns False (and bugfix-validation treats it the same).
But the two `/mc admin config set` webhook calls used strict=True, so on a
non-zero exit Shell.run raises RuntimeError (utils.py) before the
`if not res:` branch could set minio_setup_error and return False. That
turned a webhook-config failure into a hard "Start ClickHouse Server"
failure (defeating the non-fatal guarantee this PR preserves) and still did
not persist the reason for CIDB.

Run every step non-strict in a (description, command) loop and, on the first
failing step, record the concrete failing sub-step in minio_setup_error and
return False. The caller persists that string via set_info, so a
webhook-config failure now stays non-fatal and lands in test_context_raw
naming the exact step instead of raising or collapsing into the opaque
umbrella.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Completes the observability half of this PR for the last opaque setup
sub-cause: stateful-data preparation.

prepare_stateful_data() ran a large bash blob via Shell.check() and
returned only a boolean, so when one of its dataset queries failed
(intermittently on the slow msan bugfix-validation leg under shared-runner
host load) the bugfix-validation re-prepare path could only report the
generic "failed to re-prepare stateful data". The concrete failing
sub-command and the ClickHouse client error never reached Result.info /
CIDB test_context_raw, collapsing this sub-cause into the opaque
"Cannot start clickhouse-server" umbrella.

Now prepare_stateful_data() runs the blob via Shell.run (same bash
executable, so `set -e`/`set -o pipefail` still apply) with a log file, an
ERR trap that records which sub-command failed, and on a non-zero exit
captures the log tail into self.stateful_setup_error. Both callers
(the START stage and the bugfix-validation re-prepare leg) prefer that
concrete reason over the generic message. Success semantics are unchanged
(returncode == 0); on the success path no error is set.

This is observability only: no retry/timeout band-aids are added (the blob
is non-idempotent and the host-load flake is not locally reproducible).
Making the real reason visible is the prerequisite for any later targeted
reliability fix.

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

Copy link
Copy Markdown
Collaborator Author

Follow-up commit 633f156: prepare_stateful_data() was the one setup sub-cause still collapsing into the generic message. It now runs its bash blob via Shell.run (same /bin/bash, so set -e/set -o pipefail still apply) with a log file + an ERR trap, and on non-zero exit captures the failing sub-command and the ClickHouse error tail into self.stateful_setup_error. Both callers (START stage and the bugfix-validation re-prepare leg) prefer that concrete reason. This makes the intermittent Environment setup (*_msan) re-prepare ERROR diagnosable in CIDB instead of opaque. Control flow and success semantics unchanged (returncode == 0); observability only, no retry/timeout band-aids.

Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes (mechanism, not the host-load timing). Driving the new capture logic with a deliberately-failing stateful sub-command (clickhouse-client exits non-zero -> set -e aborts -> ERR trap fires) deterministically yields stateful_setup_error = "stateful data prep failed (exit N): <failing line + CH error>" every run; the all-true blob yields None. The underlying flake itself is host-load timing on the slow msan leg and is not locally reproducible by design.
b Root cause explained? Yes. prepare_stateful_data() ran a large bash blob via Shell.check(), which returns only a bool and logs to /dev/null. When one dataset query failed (intermittently on the msan leg under shared-runner host load), the failing sub-command + ClickHouse error were discarded, so the re-prepare path could only report the generic "failed to re-prepare stateful data" and the sub-cause collapsed into the opaque "Cannot start clickhouse-server" umbrella.
c Fix matches root cause? Yes. Capture the concrete reason (Shell.run + log file + ERR trap + log-tail) into stateful_setup_error and surface it through the existing reprepare_error/SETUP FAILURE paths, exactly mirroring the minio_setup_error pattern this PR already added. No band-aids: no retry, no timeout bump, no test weakening.
d Test intent preserved / new tests added? Yes. No test assertions touched. The ERROR-on-failed-reprepare guard (which prevents false bug "reproductions") is unchanged; only the info string is enriched. Demonstrated via a standalone harness exercising the exact new capture block in both directions.
e Both directions demonstrated? Yes. Failure direction: concrete failing sub-command + exit code + CH error now reach stateful_setup_error and the Environment setup (<bt>) ERROR row info. Success direction: returns True, stateful_setup_error is None, no spurious error.
f Fix is general across code paths? Yes. Both prepare_stateful_data() callers are updated (initial START stage and the bugfix-validation re-prepare leg). Both use CH.stateful_setup_error or "<generic>", so neither regresses when the field is unset.
g Fix generalizes across inputs? N/A (CI-harness Python control-flow/observability change, not a datatype/engine code path).
h Backward compatible? N/A (CI-internal harness; no settings, on-disk/wire formats, or user-facing behavior changed).
i Invariants and contracts preserved? Yes. set -e/set -o pipefail preserved (Shell.run uses executable=/bin/bash); success semantics identical to Shell.check (returncode == 0). The non-fatal-vs-fatal control flow is unchanged. stateful_setup_error is reset at entry so it never carries a stale value across legs.

Session id: cron:clickhouse-worker-slot-1:20260629-171300

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger — 633f156999f80e513b07e4334382a758e0a1ec

CI fully finished (Finish Workflow + Mergeable Check passed). Bugfix validation, Stateless, builds and Style are green on this head. Every red check below has an owner.

Check / test Reason Owner / fixing PR
Stress test (amd_tsan) / Hung check failed, possible deadlock found chronic stress-wide shutdown deadlock (1310 hits / 544 PRs / 382 master, 30d); not PR-caused (this is a CI-harness observability change in clickhouse_proc.py + functional_tests.py, cannot affect server-side stress shutdown) #101680 / #105905 (ours, open)
Stress test (arm_tsan) / Hung check failed, possible deadlock found same hung-check deadlock family #101680 / #105905 (ours, open)
CH Inc sync private fork-sync mirror CH Inc sync (private, not actionable by us)

Session id: cron:our-pr-ci-monitor:20260629-220000

Comment thread ci/jobs/scripts/clickhouse_proc.py Resolved
The replica_num == 0 guard around _flush_system_logs() reads as
'flush only replica 0', but _flush_system_logs() already iterates
every running replica (self.proc, self.proc_1, self.proc_2). The
guard only prevents the recursive wait_ready(1/2) calls from
re-running the fan-out. Comment-only change.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Comment thread ci/jobs/functional_tests.py Resolved
Comment thread ci/jobs/scripts/clickhouse_proc.py Resolved
groeneai and others added 3 commits June 30, 2026 11:48
Two observability completeness fixes for the bugfix-validation re-prepare
path, so the persisted "Environment setup" row names what actually failed
instead of collapsing into the generic "failed to re-prepare stateful data"
bucket this PR is splitting.

1. functional_tests.py: split the prepare_stateful_data() /
   insert_system_zookeeper_config() boolean chain like the START stage
   already does. Previously a successful data prep followed by a failing
   insert_system_zookeeper_config() still reported "failed to re-prepare
   stateful data", pointing at the wrong operation. Now the zookeeper-config
   failure sets reprepare_error = "insert_system_zookeeper_config failed".

2. clickhouse_proc.py: include $BASH_COMMAND in the prepare_stateful_data ERR
   trap. The trap recorded $LINENO + exit code but not the command itself, so
   stateful_setup_error still required reconstructing the generated shell blob
   to find the failing query. It now carries the command text.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Resolve conflict in ci/jobs/scripts/clickhouse_proc.py: master refactored
the clickminio restart into a robust retried _force_restart_minio() fallback
(ClickHouse#108821 env-setup flake). Keep that fallback and re-apply this branch's
observability: record self.minio_setup_error when both the clean and manual
restarts fail, so the reason still reaches the setup Result / CIDB.

ci/jobs/functional_tests.py auto-merged cleanly.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
On the terminal non-fatal restart path the clean mc admin service restart
status/timeout and the manual _force_restart_minio failure reason were only
printed, not carried into minio_setup_error. Because minio setup can still
succeed overall, from_commands_run does not persist those prints into
Result.info, so a restart failure collapsed back into a generic CIDB bucket.

_force_restart_minio now returns None on success or a concrete reason string,
and _restart_minio_to_apply_config records the clean-restart status and the
manual-restart reason into minio_setup_error before returning False. Success
semantics are unchanged.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@Algunenano
Algunenano added this pull request to the merge queue Jul 1, 2026
Merged via the queue into ClickHouse:master with commit 02dd674 Jul 1, 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 Jul 1, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Reliability follow-up to the observability work here: the msan stateful re-prepare host-OOM (Code 241 on INSERT ... max_insert_threads=16, surfaced by this PR's plumbing) is now fixed by lowering insert-thread concurrency on sanitizer legs in #109954.

pull Bot pushed a commit to AKJUS/ClickHouse that referenced this pull request Jul 10, 2026
The bugfix-validation job swaps in each sanitizer binary and re-runs
prepare_stateful_data(). On the msan leg the server's baseline RSS
already sits near max_server_memory_usage (the host RSS ceiling), so
the re-prepare INSERTs running with max_insert_threads=16 push the
total memory tracker over the limit and fail with

  Code: 241. DB::Exception: (total) memory limit exceeded: would use
  19.53 GiB ..., current RSS: 53.62 GiB, maximum: 53.62 GiB ...
  (query: INSERT INTO test.hits_s3 SELECT * FROM test.hits
   SETTINGS ... max_insert_threads=16)

This surfaces as an 'Environment setup (*_msan)' ERROR (the concrete
reason is now visible thanks to the observability plumbing in ClickHouse#108593).

Lower max_insert_threads to 4 when the binary under test is a sanitizer
build (asan/tsan/msan/ubsan), keeping 16 for non-sanitizer builds. The
exact same data is loaded; only the transient per-insert working set
shrinks. The ERROR-on-failed-reprepare guard is unchanged.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…se-server-setup-flush-noise

Fix misleading Code 210 and opaque failures in functional-test server setup
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The bugfix-validation job swaps in each sanitizer binary and re-runs
prepare_stateful_data(). On the msan leg the server's baseline RSS
already sits near max_server_memory_usage (the host RSS ceiling), so
the re-prepare INSERTs running with max_insert_threads=16 push the
total memory tracker over the limit and fail with

  Code: 241. DB::Exception: (total) memory limit exceeded: would use
  19.53 GiB ..., current RSS: 53.62 GiB, maximum: 53.62 GiB ...
  (query: INSERT INTO test.hits_s3 SELECT * FROM test.hits
   SETTINGS ... max_insert_threads=16)

This surfaces as an 'Environment setup (*_msan)' ERROR (the concrete
reason is now visible thanks to the observability plumbing in ClickHouse#108593).

Lower max_insert_threads to 4 when the binary under test is a sanitizer
build (asan/tsan/msan/ubsan), keeping 16 for non-sanitizer builds. The
exact same data is loaded; only the transient per-insert working set
shrinks. The ERROR-on-failed-reprepare guard is unchanged.

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 manual approve Manual approve required to run CI 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