Skip to content

Fix flaky test_default_session_user config-reload tests racing with the background config reloader - #116109

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-default-session-user-config-reloader-race
Aug 24, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-default-session-user-config-reloader-race

Conversation

@groeneai

@groeneai groeneai commented Aug 24, 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_default_session_user/test.py::test_config_reload_prometheus_handlers_switch_to_fixed_user
failed twice on master today on Integration tests (amd_msan, 1/8), and is clean on every other check
variant that ran it (master, 30 days: 60 OK, 2 FAIL). No related open issue. The test landed with #110179.
CI report

Root cause. A listener's restart decision in updateServers compares the incoming config against
the config recorded by the previous reload. SYSTEM RELOAD CONFIG is not the only reloader: the
background ConfigReloader polls every config_reload_interval_ms (default 2000 ms) and detects
change by config-file mtime, which replace_in_config's sed -i bumps. A poller tick landing between
a test's edit and its explicit reload consumes the difference, so the test's own reload compares an
edited config against an edited config and logs nothing. In the failing run a poller reload started
352 ms before the test's own reload and emitted the three will reload lines with no query id; the
test's SYSTEM RELOAD CONFIG then logged no listener lines at all.

Change. Pin config_reload_interval_ms to one hour for the module's three instances, so
SYSTEM RELOAD CONFIG is the only reloader and the one-edit-set-to-one-reload assumption these tests
already make actually holds. This follows the existing idiom in test_zookeeper_connection_log and
test_shard_names. Test-only: no assertion changed, no test removed, no server default altered.

This also repairs three assert not contains_in_log sites that were passing vacuously: a negative
assertion is satisfied whenever the poller already consumed the edit, so it failed silently open. No
polling scheme could fix those; only removing the competing reloader can.

Validation. Forcing the race (50 ms poller, 1 s gap between the two edits) reproduces the exact CI
assertion 20/20, with the line absent from the whole server log. With the fix under the same forcing,
20/20 pass and the line appears with the reload query's own query id. Full module 29/29 green.


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

Version info

  • Merged into: 26.9.1.40 (included in 26.9 and later)
  • Backported to: 26.8.3.20

… reloader

test_config_reload_prometheus_handlers_switch_to_fixed_user failed twice on
master on Integration tests (amd_msan, 1/8) with the endpoint's
<default_session_user> restart line missing from the server log.

A listener's restart decision in updateServers compares the incoming config
against the config recorded by the previous reload. SYSTEM RELOAD CONFIG is
not the only reloader: the background ConfigReloader polls every
config_reload_interval_ms (default 2000 ms) through the same updater, keyed on
the config file's mtime, which replace_in_config's sed -i bumps. When a poller
tick lands between a test's config edit and its explicit reload, the poller
consumes the difference and records the edited config; the explicit reload then
compares an edited config against an edited config, decides nothing changed,
and logs nothing. In the failing run the three "will reload" lines carry no
query id and run on the poller thread 352 ms before the test's SYSTEM RELOAD
CONFIG, which logged no listener lines at all. The <default_session_user>
variant is lost rather than merely late, because it is gated on the handler set
consuming the setting, which the same edit removes.

Pin config_reload_interval_ms to one hour for the module's three instances, so
SYSTEM RELOAD CONFIG is the only reloader and the one-edit-set-to-one-reload
assumption these tests already make actually holds. This follows the existing
idiom in test_zookeeper_connection_log and test_shard_names.

The same change also repairs three "assert not contains_in_log" sites, which
were passing vacuously under this race: a negative assertion is satisfied
whenever the poller already consumed the edit, so it failed silently open. No
polling scheme could fix those, only removing the competing reloader.

Forcing the race (a 50 ms poller and a 1 s gap between the two edits)
reproduces the exact CI assertion 20 times out of 20, with the line absent from
the whole server log. With this change under the same forcing, 20 of 20 pass
and the line appears attributed to the reload query's own query id. The full
module is 29 of 29 green.

Related: ClickHouse#110179
Nothing observed the pinned interval, so dropping the config fragment from an
instance's main_configs, deleting the file, or mistyping the value would
silently fall back to the 2000 ms default and leave the module green most of
the time, since the race only fires when a poller tick happens to land in the
narrow window between a test's config edit and its explicit reload. A revert
that stays green is exactly what a regression test has to prevent.

Assert in started_cluster, which every test in the module goes through, that
each of the three instances reports config_reload_interval_ms = 3600000, using
the system.server_settings form that test_config_reloader_interval already
uses. The value is published on the initial config load, before any reload is
needed, so the read is a plain point-in-time query with no polling and no log
window to match against.

The assertion is the positive form on purpose. An "absence of 2000ms" oracle
would be permanently false, because the users config reloader logs its own
"Config reload interval set to 2000ms" line on the same server.

Removing the fragment from node_reject alone makes the fixture fail with
"assert '2000' == '3600000'", so the assertion discriminates per instance and
reads the real default rather than erroring out. Restored, the module is 29 of
29 green.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Aug 24, 2026
@groeneai

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

Independent cold review of the resulting diff plus a second-model gate pass, adjudicated against the
recorded validation evidence. Two review rounds: the first surfaced a test-liveness gap that was fixed
before publication; the second found nothing.

# Finding Verdict
❌ The pinned reload interval was not observed anywhere: the fragment was only wired into main_configs, and the module fixture asserted nothing about it. Dropping the fragment would leave the suite green, because the underlying failure only fires when a poller tick happens to hit a narrow edit-to-reload window. Agreed, fixed. The fixture now asserts the effective interval per instance via system.server_settings, following the test_config_reloader_interval idiom. Verified by mutation: removing the fragment from one instance reddens the assertion with assert '2000' == '3600000', so it reads the real default rather than erroring out.
⚠️ The new config file's comment narrated the defect mechanism rather than stating the local invariant. Agreed, fixed. Trimmed to the invariant; the mechanism stays in the commit message.
💡 Reformat the three edited main_configs lines per black. Not applied. black is not run by CI (ci/jobs/check_style.py has ruff, pylint and mypy only); ruff passes at its 200-char limit; and the file already fails black --check at the unmodified base revision, with 71 pre-existing lines over 88 chars. The added lines keep the exact shape of the lines they replace.
💡 Four other integration modules share the same shape (a config edit, an explicit SYSTEM RELOAD CONFIG, and a log assertion, with no pinned interval): test_insert_deduplication_version_guard, test_keeper_nodes_add, test_refreshable_mv, test_startup_scripts. Noted, out of scope. None has a single failure on master in 30 days, so there is nothing observed to fix and I am not widening this PR to four unrelated modules. Recording it here rather than acting on it.
💡 The interval pin does not close every path into the main reloader: the cgroup-memory observer also calls it directly (Server.cpp:3352), a forced reload outside the interval. Noted, out of scope. It is event-driven on a change of the memory amount available to the process (CgroupsMemoryUsageObserver.cpp:70-81), and the failing run's server log records no such change, so it is not a carrier of this failure. Measured post-fix too: the only reload without a query id is the one at startup.

Also checked and clean: the root cause was re-derived from source independently (updateServers
compares against the config recorded by the previous reload; the poller and SYSTEM RELOAD CONFIG
drive the same single updater; change detection is mtime-keyed and covers config.d), and confirmed
against the archived CI log, where the restart line is absent from the whole file rather than late.
That is also why a polling oracle would not have worked: the line is gated on the handler set
consuming the setting, so once the poller has recorded the new set the line can never appear.
The one-hour interval has no escape hatch in this module either: the reloader's wait is on a ZooKeeper
change event, and the module declares no ZooKeeper instance and no from_zk include, so the event is
never set. No test here depends on background auto-reload: all 10 replace_in_config sites are
followed by an explicit SYSTEM RELOAD CONFIG. No assertion was weakened and no test removed or
skipped (29 test functions before and after, all 11 log assertions unchanged). Shutdown is unaffected
by the one-hour interval, because the reloader's stop() signals its wait before joining.

Session ids: cron:clickhouse-review-slot-9:20260824-114600, cron:clickhouse-review-slot-8:20260824-125100

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Forcing the race (a 50 ms config_reload_interval_ms on node_reject plus a 1 s gap between the two replace_in_config calls) fails 20/20 with the exact CI assertion. Verified against four criteria: message identical to CI; grep -c "default_session_user> had been changed" = 0 in the whole log (absent, not late; log runs on to Stop SignalListener thread); the three will reload lines carry no query id on thread 200 while the reload query is thread 18 {fc363058...} 1.08 s later; and that query id logs 0 will reload and 0 Stopped listening lines.
b Root cause explained? Yes. updateServers decides a listener's restart by diffing the incoming config against the config recorded by the previous reload. The background ConfigReloader polls every config_reload_interval_ms (default 2000 ms, ConfigReloader.h:24) through the same updater, keyed on config-file mtime, which replace_in_config's sed -i bumps. A tick landing between a test's edit and its explicit reload consumes the delta, so the explicit reload compares edited against edited and logs nothing. The <default_session_user> line is lost rather than late because it is gated on the handler set consuming the setting (Server.cpp:4767-4769, :4040-4058), which the same edit removes.
c Fix matches root cause? Yes. It removes the competing reloader, which is the cause, rather than retrying or relaxing the observation. No timeout increase, no no-random-* tag, no weakened assertion, no defensive guard.
d Test intent preserved / new tests added? Yes. No assertion changed and no test removed or skipped (29 test functions before and after). Coverage strictly increases: three assert not contains_in_log sites that were passing vacuously become sound. No new test is added because the existing tests are the coverage and they were unsound. The started_cluster fixture now asserts each instance reports config_reload_interval_ms = 3600000, so dropping the config fragment reddens the module instead of silently restoring the default.
e Both directions demonstrated? Yes. Pre-fix under forcing: 0 pass / 20 fail. Post-fix as committed: 20 pass / 0 fail. Negative control keeping the forced 1 s gap and swapping only the poller interval for the fix: the test passes and the previously absent line appears attributed to the reload query's own query id ({a850e474...}, thread 17), with the count moving 0 to 1.
f Fix is general across code paths? Yes. Applied to all three instances, not only the failing one, so all 11 contains_in_log and all 10 replace_in_config sites in the module are covered. updateServers has exactly one caller (Server.cpp:2983) and main_config_reloader is the only reloader reaching it, so no sibling path stays racy. The cgroup-memory observer (Server.cpp:3352) was checked as a possible second reloader and measured not to fire: in every post-fix log the only reload without a query id is the startup one. The fixture assertion covers all three instances for the same reason, so a fragment dropped from any one of them is caught.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A for a reload-interval setting: there are no type wrappers or boundary values. The equivalent axis is which reload shapes are covered, and all are: single-edit tests, multi-sed tests, positive and negative log assertions, and all three instances.
h Backward compatible? (maintainer-approved exception only) Yes, and no exception is needed. Test-only change. config_reload_interval_ms is a ServerSetting (src/Core/ServerSettings.cpp:1293) whose default is unchanged; the value is supplied per-instance via main_configs, so no SettingsChangesHistory.cpp entry applies and no product behaviour changes.
i Invariants and contracts preserved? Yes. No test relies on background auto-reload: all 10 replace_in_config sites are followed by an explicit SYSTEM RELOAD CONFIG. Shutdown is unaffected because ConfigReloader::stop() sets quit and zk_changed_event->set() before join() (ConfigReloader.cpp:57-68), so the poller wakes regardless of interval; corroborated by test_zookeeper_connection_log already running at 3600000 and by 29/29 tests passing with clean cluster shutdown.

Session id: cron:clickhouse-review-slot-8:20260824-125100

@clickhouse-gh

clickhouse-gh Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4b42e04]

Summary: ✅


AI Review

Summary

This PR pins config_reload_interval_ms to 3600000 for all three test_default_session_user instances and asserts the effective value in the module fixture, which matches the reported race between the background ConfigReloader and the tests' explicit SYSTEM RELOAD CONFIG calls. I re-checked the current diff against the full test module, the relevant ConfigReloader / server reload paths, the prior PR discussion, and the current PR CI, and I did not find an unresolved correctness, coverage, or safety issue.

Final Verdict
  • Status: ✅ Approve

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @azat, could you review this? Test-only: the module's tests assume SYSTEM RELOAD CONFIG is the only reloader, but the background ConfigReloader polls every 2000 ms on the same updater, so a tick landing between a test's config edit and its explicit reload consumes the delta and the explicit reload then sees no change; pinning config_reload_interval_ms to one hour for the three instances restores that assumption.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Aug 24, 2026
@PedroTadim PedroTadim self-assigned this Aug 24, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 4b42e0424 with master 762e8e123 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 709.21 MiB 706.16 MiB -3.04 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 24, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 4b42e04

CI fully finished and no check failed, so no ledger row is owed.

Gate (a) no check queued/in_progress (182 runs, 175 unique) - gate (b) Finish Workflow
completed/success, Config Workflow and Style check likewise green - gate (c) last completed
check +55.0 min - gate (d) vacuously satisfied, zero failures to own.

Corroboration: praktika result_pr.json root OK, all 175 nodes in {OK, SKIPPED} (positive
control Finish Workflow present). Not a void run (Config OK + Style OK is the inverse of the
void discriminator). CIDB at this head returns zero non-green rows against a control of
28,358 rows at the same commit, so that zero is a real filtered subset and not an empty or
broken query.

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

Merged via the queue into ClickHouse:master with commit 073712a Aug 24, 2026
185 of 187 checks passed
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 24, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 3, 2026
@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 Sep 3, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 3, 2026
Backport #116109 to 26.8: Fix flaky test_default_session_user config-reload tests racing with the background config reloader
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 4, 2026
…er config-reload tests racing with the background config reloader
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 groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-ci 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 v26.8-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants