Skip to content

Pass --allow_repeated_settings when collecting server stacktraces - #112845

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/allow-repeated-settings-stacktrace-collection
Aug 5, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/allow-repeated-settings-stacktrace-collection

Conversation

@groeneai

@groeneai groeneai commented Aug 1, 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

get_stacktraces_from_clickhouse in tests/clickhouse-test builds a clickhouse-client command
line that can carry the same setting twice, and then dies before querying anything:

Bad arguments: option '--max_untracked_memory' cannot be specified more than once

The duplication is intended. get_additional_client_options concatenates the
CLICKHOUSE_CLIENT_OPT copy of --client-option with --client-option itself, so that
user-supplied values come last and win; that is the documented last-occurrence-wins override.
add_effective_settings makes it safe by appending --allow_repeated_settings to the environment
while a test runs, but remove_settings_from_env resets the variable to the flagless startup
snapshot in a finally block after every test. This collector is reached from the end-of-run hung
check and from the per-test timeout handler, where the flag may not be set, so it assembles the
command with the duplicates and without the flag, and clickhouse-client exits 36.

The consequence is a diagnostics loss: a hung-check report loses its system.stack_trace dump
entirely, which is the only view that maps a stuck thread to the query it was running. The
Hung check failed verdict itself is decided elsewhere, so no CI result changes. It has been
observed on master as well as on pull requests.

This adds the flag where the command line is assembled, matching what add_effective_settings
already does for the ordinary test path. All three query branches share the single settings_str,
so one line covers them.

An observed failure: Stress test (arm_tsan) on #109368.

Validation: driving the real function against a live server returns 0 bytes with exit status 36
before the change and a 332 KB dump containing thread_name after it. The new test in
ci/tests/test_print_stacktraces.py asserts both that the assembled options really are duplicated
and that a dump comes back; reverting the one-line change reddens it with the message above.

Related: #109368

Version info

  • Merged into: 26.8.1.871 (included in 26.8 and later)

groeneai added 2 commits July 31, 2026 22:58
get_stacktraces_from_clickhouse builds a clickhouse-client command line from
get_additional_client_options, which deliberately concatenates the
CLICKHOUSE_CLIENT_OPT copy of --client-option with --client-option itself so
that user-supplied values, coming last, win over the randomized settings. Any
setting given both ways therefore appears twice on the command line.

That is harmless while a test is running: add_effective_settings appends
--allow_repeated_settings to the environment for the duration of the test. But
remove_settings_from_env resets CLICKHOUSE_CLIENT_OPT to the flagless startup
snapshot in a finally block after every test, and this collector runs precisely
outside a test: from the per-test timeout handler and from the end-of-run hung
check. Without the flag clickhouse-client exits 36 with "Bad arguments: option
'--max_untracked_memory' cannot be specified more than once", so the hung-check
report loses the system.stack_trace dump entirely.

Add the flag where the command line is assembled, matching what
add_effective_settings already does for the ordinary test path. All three query
branches share the single settings_str, so one line covers them.

Related: ClickHouse#109368
Comment text only. The two comment blocks added by the previous commit
named functions, options and a log excerpt as bare text; `.claude/CLAUDE.md`
requires literal names from ClickHouse SQL, classes and functions, and
literal excerpts from log messages to be wrapped in inline code blocks.
Names are written as `f`, not `f()`, as the same file requires.

The comment in `tests/clickhouse-test` also said this collector "runs
outside" a test. That is right for the end-of-run hung check, but
`print_sql_stacktraces` is also reached from the per-test SIGALRM
`timeout_handler`, which is armed around both `run` and `process_result`,
so the environment may or may not carry `--allow_repeated_settings` at
that moment. The comment now says the flag is added while a test runs and
names both call sites. The fix is correct in either case because the flag
is consumed in the argv pre-scan and is not forwarded to
`boost::program_options`, so a second copy is idempotent.

No behavioural change: stripping comments from both files before and
after this commit yields byte-identical token streams, and `ast.dump` of
each file is unchanged.
@groeneai

groeneai commented Aug 1, 2026

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

Two review rounds, each an independent cold read of the resulting code followed by a separate
second-model pass. Round 1 raised two wording nits and no correctness findings; round 2, after those
were fixed, returned zero findings from both passes. Nothing about the executable change moved
between the rounds.

Round 1 (2 nits, both fixed)

⚠️ .claude/CLAUDE.md requires literal names and log excerpts in inline code blocks. Both added
comment blocks named functions and quoted the client's error text as bare prose. The surrounding
file already follows the rule in 69 inline comments, so this was an omission rather than a house
style. Fixed: every one of --client-option, CLICKHOUSE_CLIENT_OPT,
get_additional_client_options, add_effective_settings, --allow_repeated_settings,
remove_settings_from_env, clickhouse-client and the excerpt cannot be specified more than once
is now backticked, and names are written as f rather than f() as the same file requires.

⚠️ The comment said this collector "runs outside" a test, which is only partly true.
print_sql_stacktraces is reached from two places: the end-of-run hung check, and the per-test
SIGALRM timeout_handler, which is armed around both run and process_result. So it can fire
while a test is still inside run, where the environment does carry the flag. Fixed: the comment now
says the flag is added while a test runs and names both call sites. The change is correct in either
case, because --allow_repeated_settings is matched in the argv pre-scan in
Client::readArguments, which sets a flag and does not forward the token to
boost::program_options, so a second copy is idempotent.

The round-1 fix was comment text only. Semantic equivalence was proved two ways rather than by
reading the diff: stripping comments from both files yields byte-identical token streams, and
ast.dump of each file is unchanged. Both checks were run with a deliberately differing control so
neither can pass vacuously.

Round 2 (clean)

Both passes returned zero findings. Re-verified independently against the current master rather
than only against the branch point:

💡 get_stacktraces_from_clickhouse is the only consumer of get_additional_client_options that
builds a client command line. Every f-string interpolating args.client anywhere in the file is one
of that function's three query branches, all fed by the single settings_str, so one line covers
them. run_diagnose_from_artifacts and run_tests_array both route through TestCase.run into
add_effective_settings, whose flag append is unconditional; every sibling collector in the same
hung-check block uses the HTTP helper instead of the CLI. No sibling change is owed.

💡 The multitoken registration the flag switches on absorbs only tokens that do not begin with -,
and every token in settings_str is --key=value or a bare --flag with --query immediately
following, so no value can be swallowed.

💡 The new test fails closed. Before the change shell_get_output swallows the non-zero exit and
returns an empty string, so the dump assertion fails with the client's own message; two premise
assertions make the test fail on its premise rather than pass trivially if the duplication ever
stops happening.

master has advanced since the branch point and has touched tests/clickhouse-test, so this was
re-checked: git merge-tree reports no conflicts, the merged tree carries both the new line and the
new test, the nearest hunk in master is over a thousand lines away, and its diff touches no line
mentioning any symbol in this mechanism.

Session id: cron:clickhouse-review-slot-11:20260801-012000

@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, 100% deterministic, not a rate. One command: clickhouse client <any setting repeated> -q "SELECT 1" exits 36 with Bad arguments: option '--max_untracked_memory' cannot be specified more than once. Driving the real get_stacktraces_from_clickhouse with the environment state present at hung-check time returns 0 bytes every time.
b Root cause explained? Yes. Startup copies --client-option into CLICKHOUSE_CLIENT_OPT without the tolerating flag, so get_additional_client_options returns the same settings twice (deliberately: that concatenation is the last-occurrence-wins override). add_effective_settings appends --allow_repeated_settings only while a test runs, and remove_settings_from_env resets the variable to the flagless startup snapshot in a finally block afterwards. This collector is reached from the end-of-run hung check and from the per-test timeout handler, where the environment may not carry the flag, so it assembles the command with duplicates and no flag and clickhouse-client exits 36.
c Fix matches root cause? Yes. The duplication is a deliberate contract; the defect is that this one consumer builds a client command line without declaring it tolerates repeats. The fix adds exactly that declaration, the same idiom add_effective_settings already uses. Nothing is widened, disabled or tagged. De-duplicating inside the helper was rejected because it would change override semantics for every consumer, and adding the flag at startup was rejected because it would change the contract for every .sh test.
d Test intent preserved / new tests added? New test added in ci/tests/test_print_stacktraces.py. It reproduces the environment state at hung-check time and pins two properties: the premise (the assembled options really are duplicated, and the flag is absent from the helper's output) and the outcome (a non-empty dump containing thread_name). No existing test was weakened and no reference file changed.
e Both directions demonstrated? Yes. Before: 0 bytes returned, returned non-zero exit status 36, Bad arguments ... more than once. After: 332265 bytes containing thread_name. Reverting the one added line reddens the new test with that same message, in a full 527-test run where nothing else changes.
f Fix is general across code paths? Yes. An AST walk enumerated all four consumers of get_additional_client_options: only get_stacktraces_from_clickhouse builds a raw client command line; run_diagnose_from_artifacts and run_tests_array both route through TestCase.run into add_effective_settings, whose final flag append is unconditional, and the fourth site is the producer that writes the environment variable. The three query branches share one settings_str, so the single line covers all three. Every sibling collector in the same hung-check block uses the HTTP helper rather than the CLI, so no sibling hunk is owed.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. The flag covers exactly the class of options that can duplicate, namely settings-style options routed through the environment copy; --secure is appended after that copy so it is never doubled. Measured at the boundaries: no duplicates (inert, max_threads reads 5 with and without the flag), duplicates present, flag before and after the duplicated block, flag itself doubled, and both value orders confirming last-occurrence-wins (3 then 7 gives 7; 7 then 3 gives 3).
h Backward compatible? (maintainer-approved exception only) Yes, trivially. tests/clickhouse-test is not a shipped artefact, no setting default changes, and no server behaviour moves, so no SettingsChangesHistory.cpp entry and no gating are owed.
i Invariants and contracts preserved? Yes. The last-occurrence-wins contract of get_additional_client_options is untouched and was re-measured. In the reported failure the duplicated values are identical, so last-wins is a no-op there. settings_str remains a single space-joined string interpolated identically into all three branches, and the added element is a constant in a list literal, so no error or early-return path is affected. The flag is accepted by clickhouse-client and is semantically inert when nothing repeats.

Session id: cron:clickhouse-impl-slot-5:20260801-010002

@groeneai

groeneai commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

cc @leshikus, could you review this? get_stacktraces_from_clickhouse assembles its client command line from get_additional_client_options, which deliberately concatenates the CLICKHOUSE_CLIENT_OPT copy of --client-option with --client-option itself, so any setting passed both ways appears twice and the client exits 36 before querying anything; the flag that tolerates repeats is only in the environment while a test runs, so the hung check loses its system.stack_trace dump.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Aug 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [59e42f4]

Summary: ✅


AI Review

Summary

This PR fixes the hung-check and timeout stacktrace collector by always passing --allow_repeated_settings when tests/clickhouse-test assembles a raw clickhouse-client command, and it adds an end-to-end regression test for the duplicated --client-option case. I did not find a correctness, coverage, or metadata issue in the current code: the change is scoped to the only affected raw CLI collector, the other get_additional_client_options call sites still flow through add_effective_settings, and the current Praktika report is all green.

Final Verdict

✅ No findings.

@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 59e42f4

Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
(none) 174 check-runs, 0 failures nothing to own

Config Workflow and Finish Workflow both completed successfully; no check queued or in progress.

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

@alexey-milovidov alexey-milovidov self-assigned this Aug 5, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 5, 2026
Merged via the queue into ClickHouse:master with commit e43e7cf Aug 5, 2026
180 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 6, 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 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