Skip to content

clickhouse local: respect --logger.level and stop progress packets from starving the result pull - #121053

Open
qoega wants to merge 4 commits into
ClickHouse:masterfrom
qoega:json-fuzz-group3-clickhouse-local-logger-level
Open

qoega wants to merge 4 commits into
ClickHouse:masterfrom
qoega:json-fuzz-group3-clickhouse-local-logger-level

Conversation

@qoega

@qoega qoega commented Sep 19, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Two clickhouse local fixes:

  1. --logger.level (and the config file's <logger><level>) is now honored; previously it was accepted but ignored, and the process always logged at trace, producing hundreds of MB of log output for long-running workloads.
  2. Any query with interactive_delay set to 0 or a value below the poll cycle no longer hangs at 100% CPU: progress and profile-event packets are now sent at most once per pull attempt, so the pull cannot be starved.

Documentation entry for user-facing changes

No documentation change needed.

Detailed description / Documentation

Commit 1 — --logger.level honored (e2d59fc1231).
LocalServer::processConfig computed the console log level only from --log-level and send_logs_level, defaulting to trace, and overwrote logger.level with it. clickhouse local --logger.console=1 --logger.level=fatal printed every trace message. Test 05235.

Commit 2 — 02360 reference adjustment (58d6434f622).
The old code's confused lookup chain let 02360_clickhouse_local_config-option pass with <level>trace</level> in the config plus --send_logs_level=none on the command line. Now that logger.level is honored, use <level>fatal</level> in that test's inline config; the test is about the --config-file option and does not need trace logging.

Commit 3 — interactive_delay starvation fix (00802165e78).
LocalConnection::poll sent a progress packet whenever interactive_delay microseconds had passed since the previous one, before trying to pull a block. With interactive_delay shorter than a poll cycle (0 or 1) that was always the case, so SELECT 1 SETTINGS interactive_delay = 0 spun at 100% CPU forever. Progress and profile-event packets are now sent at most once per pull attempt. Test 05246 (renumbered from the branch's 05243 to avoid collision with the JSON-AST hardening PR's 05243).

Both fixes surfaced from the json_ast_sql_execution_fuzzer campaign; without commit 1, worker logs grew to ~300 MB per hour, and finding 20 (commit 3) hung a worker for 73 s before the libFuzzer alarm.

Closes: #121022
Closes: #121076

cc @groeneai — fuzz-lab find (JSON AST fuzzer)

🤖 Generated with Claude Code


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

`clickhouse local` accepts `--logger.level` on the command line (and from a config
file) but `processConfig` computed the console log level only from `--log-level`
and `send_logs_level`, defaulting to `trace`, and overwrote `logger.level` with it.
So `clickhouse local --logger.console=1 --logger.level=fatal` printed every trace
message. Found while running `json_ast_sql_execution_fuzzer`, whose logs grew to
300 MB per worker in two hours.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@qoega qoega added the fuzz Problem found by one of the fuzzers label Sep 19, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [44fbdbc]

Summary: ❌

job_name test_name status info comment
Fast test FAIL
02456_progress_tty FAIL cidb
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL
Code Review DROPPED
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED
Build (amd_binary) DROPPED
Build (arm_debug) DROPPED

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 19, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-local clickhouse-local / embedded modes (incl. local file processing). label Sep 19, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

I had the same one-line change queued from your issue, with the same precedence order, so I am not opening a competing PR. Yours is the one to land. Two measured things about the source change that this PR does not carry yet.

This change makes 02360_clickhouse_local_config-option fail. That test writes a config with <logger><level>trace</level><console>true</console></logger> and merges stderr into the asserted stdout with |&. It is silent today only because the inverted chain lets its --send_logs_level=none pick the logger level. Once logger.level is consulted, the config's trace wins and the one-line reference gains 66 lines of log output (@@ -1 +1,67 @@, reproduced twice on this change). Your CI had not reached Stateless when I looked, so it has not surfaced there yet.

The remedy is one element in local_opts:

 local_opts=(
     "--config-file=$SAFE_DIR/config.xml"
+    "--log-level=none"
     "--send_logs_level=none")

It restores the reference on an unpatched binary as well as a patched one, so it is safe to carry here and does not depend on the fix landing with it. 50/50 clean.

02360 is the only test that depends on the old precedence. I swept the rest of that carrier class, meaning the other --config-file fixtures that spell the key as <logger><level> rather than as a dotted option, plus the --send_logs_level tests. They are unaffected, either because their config sets <level>none</level> with no channel enabled, or because they have no <logger> block so logging stays false and the resolved level never reaches a channel.

Coverage. 05235 asserts the console channel at two levels. The config-file <logger><level> form you asked about in the issue, and the --server_logs_file branch, which is the other consumer of the resolved level in that function, are both fixed by your statement but not asserted by it. I have measured cases for those two plus the log-level > logger.level > send_logs_level ordering, and I am happy to post them here if you want them in 05235.

…es not spam the console

Before the previous commit, LocalServer overwrote logger.level with the
fallback default, so `<level>trace</level>` in the config file was silently
ignored and the test's `--send_logs_level=none` was the only thing keeping
the console clean. Now that logger.level is honored, the config-level trace
setting starts printing every server startup log to the console.

The test is about the `--config-file` option; drop the accidental trace
level and use `fatal` so the fix does not fight the test's intent.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
echo "<clickhouse>
<logger>
<level>trace</level>
<level>fatal</level>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes 02360, but it also means the suite still never proves the config-file carrier that the PR body and the linked issue call out explicitly. With <logger><level>fatal</level> here and --send_logs_level=none below, both the buggy and fixed binaries stay silent, so this test no longer distinguishes whether LocalServer::processConfig actually consults logger.level from the config file. 05235 only exercises the CLI --logger.level path.

Please add a case where the config file sets <logger><level> to the opposite of send_logs_level (for example fatal vs trace) so the old code fails and the new code passes.

…interactive_delay is tiny

`LocalConnection::poll` returned a `Progress` packet whenever more than
`interactive_delay` microseconds had passed since the previous one, before trying
to pull a block. With `interactive_delay` shorter than a poll cycle (0 or 1) that was
always the case, so `SELECT 1 SETTINGS interactive_delay = 0` spun at 100% CPU
forever in `clickhouse local`. Progress and profile-event packets are now sent at
most once per pull attempt.

Found by `json_ast_sql_execution_fuzzer`.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@qoega qoega changed the title clickhouse local: respect --logger.level clickhouse local: respect --logger.level and stop progress packets from starving the result pull Sep 19, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

Verified commit 3 against master, and one thing it leaves open.

Both directions. Master 015bf1203d3 (debug): timeout 20 clickhouse local -q "SELECT 1 SETTINGS interactive_delay = 0" returns 124 with no output. This branch (7077382, debug): all four lines of the new 05246 return the expected values in about 0.24 s each.

The pull timeout still truncates to zero. pullBlock passes interactive_delay / 1000 (LocalConnection.cpp:565), so every value below 1000 becomes a 0 ms timeout. The SELECT path sets no cancel callback (setCancelCallback is only on the CompletedPipelineExecutor branch), so PullingAsyncPipelineExecutor::pull keeps effective_timeout = 0 and LazyOutputFormat::getChunk(0) takes the blocking queue.pop() branch instead of tryPop. The result pull is no longer starved, but the client is now parked inside one pull for the whole query, and ClientBase::receiveResult checks Ctrl+C only before connection->poll (ClientBase.cpp:1945), so the first Ctrl+C is dropped.

Measured on this branch with SELECT count() FROM numbers_mt(30000000000) WHERE sipHash64(number) % 7 = 0 (24.6 s uninterrupted), one SIGINT sent 5 s in, plus the same query over TCP against a server built from the same tree:

path interactive_delay after one SIGINT
local 100000 (default) exits in 0.2 s, cancelled, no result printed
local 1000 exits in 0.2 s, cancelled
local 999 exits in 19.2 s, runs to completion, prints 4285732496
local 0 exits in 19.2 s / 19.4 s (2 runs), same
TCP default client 0.3 s, query gone from system.processes 0.4 s
TCP 1000 0.3 s / 0.1 s
TCP 999 7.1 s / 7.2 s
TCP 0 7.0 s / 7.1 s

The discontinuity between 999 and 1000 is the truncation. Log delivery collapses the same way: with --send_logs_level=trace on that query, 40 of 56 log lines arrive while it runs at the default delay, versus 12 of 56 at interactive_delay = 0, where the other 44 arrive in a burst at the end.

The TCP half comes from TCPHandler.cpp:1624, which carries the same expression and is untouched here, so that part is pre-existing. Net effect of the setting today: asking for the most frequent progress yields none, plus a query that ignores the first Ctrl+C. Flooring both conversions at 1 ms would cover it, since 1000 already behaves correctly.

Your call whether that belongs in this PR or separately. I am not opening a competing PR for the starvation fix, yours is the one to land; I can send the floor as its own PR if you would rather keep this one narrow.

…lisecond

`interactive_delay` is in microseconds and the executors take milliseconds; a
value below 1000 truncated to a blocking pull in `LocalConnection` and
`TCPHandler`, so the first cancel was noticed only after the query. Test 02360
passes `--log-level=none` now that the configured `logger.level` is honoured, and
05235 covers the config-file level and the `--log-level` override order.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@qoega

qoega commented Sep 21, 2026

Copy link
Copy Markdown
Member Author

Review follow-up landed as 44fbdbc89ac. Three-part change on top of the existing commits:

  1. --log-level=none added to 02360's local_opts per your suggestion; the earlier <level>fatal</level> band-aid is reverted in favor of the config-file <level>trace</level> staying so the test actually distinguishes the buggy/fixed binaries.
  2. 05235 gains config-file <logger><level> cases (fatal config + send_logs_level=trace → many, --log-level=none → 0, config fatal → 0, --log-level=trace → many) and the log-level > logger.level > send_logs_level override ordering.
  3. 1 ms floor on interactive_delay / 1000 at both LocalConnection.cpp:565 and TCPHandler.cpp:1624, so a sub-1000-µs interactive_delay no longer truncates to a 0 ms executor timeout and does not park the SELECT client inside a blocking pull. First Ctrl+C is honored, log delivery does not collapse.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-local clickhouse-local / embedded modes (incl. local file processing). fuzz Problem found by one of the fuzzers pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

2 participants