Skip to content

Fix flaky test_server_no_logging: poll for async "Restored console logger level" line - #110033

Merged
alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-flaky-test_server_no_logging-async-log
Jul 10, 2026
Merged

alexey-milovidov merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/fix-flaky-test_server_no_logging-async-log

Conversation

@groeneai

@groeneai groeneai commented Jul 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

test_server_startup_and_shutdown_logs/test.py::test_server_no_logging is flaky. Failure on master:

File: test_server_startup_and_shutdown_logs/test.py:45 - in started_cluster
    assert instance_console_unset.contains_in_log(
E   AssertionError: assert False
E    +  where False = contains_in_log('Restored console logger level to logger.level')

CI report (master, arm_binary): https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=f5e40f2d86d1715c149223f478bce0460fdd8e29&name_0=MasterCI&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%204%2F4%29

Root cause: the "Restored console logger level ..." line is emitted by LOG_INFO at the very end of server init (programs/server/Server.cpp), right before ports are opened and the instance is declared ready. Logging is async by default (logger.async=true), so the background writer thread may not have flushed that final line to the log file yet when the ping handshake succeeds and the fixture runs its one-shot contains_in_log grep. The earlier "Starting console logger in level trace" checks on the same instances pass reliably because those lines are logged at the start of init, giving the writer the whole init duration to flush.

Fix: use wait_for_log_line (polls up to 30s) for the two post-startup "Restored ..." assertions. Test intent is unchanged - the same log strings must still appear.

Test-only change. The test/console-log-restore logic was added recently in dbf5f7b (fix for issue #103472); this addresses the flakiness introduced with the new fixture assertions.

Version info

  • Merged into: 26.7.1.787 (included in 26.7 and later)
  • Backported to: 26.6.2.72, 26.5.6.43, 26.4.5.131, 26.3.17.46

…gger level" line

The started_cluster fixture asserted the post-startup "Restored console logger
level ..." line with a one-shot contains_in_log grep immediately after
cluster.start() returned. That line is emitted by LOG_INFO at the very end of
server init, right before ports are opened and the instance is declared ready.
Logging is async by default (logger.async=true), so the background writer thread
may not have flushed that last line to the log file yet when the ping handshake
succeeds, causing an intermittent AssertionError. The earlier "Starting console
logger" lines pass reliably because they are logged at the start of init, giving
the writer the whole init duration to flush. Use wait_for_log_line (polls up to
30s) for the two "Restored ..." checks; intent 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? Not reproduced on this worker (integration harness/Docker build unavailable), but the exact failing assertion is captured in the CI report and the mechanism is deterministic in code: the checked line is the LAST log line of init, emitted just before the ping-ready handshake, under async logging.
b Root cause explained? Logging is async by default (logger.async=true). "Restored console logger level ..." is emitted by LOG_INFO at the very end of server init (Server.cpp), microseconds before ports open. The fixture does a one-shot contains_in_log grep the instant cluster.start() returns, so the async writer thread may not have flushed that final line to disk yet -> intermittent AssertionError.
c Fix matches root cause? Yes. wait_for_log_line polls the log file (tail -F) up to 30s, closing exactly the flush-timing window. Not a band-aid: it targets the async-flush lag, not a symptom.
d Test intent preserved / new tests added? Preserved. The same two log strings must still appear; only the wait mechanism changed from one-shot grep to bounded poll. The "Starting console logger" assertions (logged early, reliably flushed) are left unchanged.
e Both directions demonstrated? Partially: cannot run the Docker integration harness on this worker. Asymmetry is the evidence - the early-init "Starting..." lines pass reliably while only the last-emitted "Restored..." line races, which is exactly what an async-flush lag predicts. FileLog level is information throughout, so the INFO line IS written (not level-filtered), confirming a flush race rather than a missing line.
f Fix is general across code paths? Yes. Both racing assertions (console_unset and console_set instances) are converted; the non-racing contains_in_log checks are correctly left alone.
g Fix generalizes across inputs? N/A (test-only timing fix, not a code bug).
h Backward compatible? N/A (test-only change, no product behavior change).
i Invariants and contracts preserved? Yes. wait_for_log_line is the established idiom for this exact situation (45 uses across tests/integration, e.g. test_config_reloader_interval); it raises on timeout so the check remains blocking.

Session id: cron:clickhouse-worker-slot-5:20260710-180100

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @garrettthomas - could you review? Your recently-added node_console_unset/node_console_set fixture assertions are flaky on master: the "Restored console logger level ..." line is logged at the very end of init under async logging, so a one-shot contains_in_log grep races the async writer's flush. This switches those two checks to wait_for_log_line (30s poll); the same strings are still required.

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

clickhouse-gh Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [47a0bc3]

Summary: ✅


AI Review

Summary

This PR replaces two one-shot contains_in_log checks in test_server_no_logging with wait_for_log_line for the post-startup "Restored console logger level ..." messages. I found no remaining correctness or test-contract issues: the referenced failing master logs already contain both "Restored ..." lines immediately before the "Listening for ..." / "Ready for connections." messages, and each per-instance startup log is only 76 lines long, so the helper's tail -n10000 window preserves the assertion while closing the async flush race.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 10, 2026
@alexey-milovidov alexey-milovidov self-assigned this Jul 10, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

I love your work!

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Jul 10, 2026
Merged via the queue into ClickHouse:master with commit 85d9f49 Jul 10, 2026
176 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 11, 2026
@Felixoid Felixoid added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Jul 15, 2026
@Felixoid

Copy link
Copy Markdown
Member

Added must backport to fix flaky #109858 in releases

@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jul 15, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Jul 15, 2026
…async "Restored console logger level" line
clickhouse-gh Bot added a commit that referenced this pull request Jul 15, 2026
Backport #110033 to 26.6: Fix flaky test_server_no_logging: poll for async "Restored console logger level" line
alexey-milovidov added a commit that referenced this pull request Jul 16, 2026
Backport #110033 to 26.5: Fix flaky test_server_no_logging: poll for async "Restored console logger level" line
alexey-milovidov added a commit that referenced this pull request Jul 16, 2026
Backport #110033 to 26.4: Fix flaky test_server_no_logging: poll for async "Restored console logger level" line
alexey-milovidov added a commit that referenced this pull request Jul 16, 2026
Backport #110033 to 26.3: Fix flaky test_server_no_logging: poll for async "Restored console logger level" line
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 16, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
… poll for async "Restored console logger level" line
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
… poll for async "Restored console logger level" line
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
… poll for async "Restored console logger level" line
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…-test_server_no_logging-async-log

Fix flaky test_server_no_logging: poll for async "Restored console logger level" line
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-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

7 participants