Skip to content

Skip a setting value from the server's Hello that this version rejects instead of failing the connection - #131636

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-hello-settings-skip-invalid-values
Nov 16, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-hello-settings-skip-invalid-values

Conversation

@groeneai

@groeneai groeneai commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #131506
Related: #131269
Related: #131194

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 into CHANGELOG.md):

Fixed connecting over the native protocol (clickhouse-client, remote, Distributed without an interserver secret) to an older server whose settings profile has a negative or overflowing value of a Seconds setting, for example max_execution_time = -1: the connection failed with A setting's value in seconds cannot be negative. Such a value sent by the server is now skipped with a warning.

Description

With #131269 (master, and the 26.10 branch since #131472), clickhouse-client or a remote() / Distributed query cannot connect to an older server whose user or profile has max_execution_time = -1 (or the obsolete drain_timeout = -1): Code: 36 ... cannot be negative. Got -1. (BAD_ARGUMENTS) at the handshake. --apply_settings_from_server=0 does not help, and a -1 in the server's default profile breaks every user. Clusters with an interserver secret are not affected.

Connection::receiveHello reads the settings the server sends with the same strict BaseSettings::read the server uses for a client's query settings. There an unknown non-important setting was already only a warning, but a known one with a value this version rejects aborted the whole handshake.

BaseSettings::read gets an opt-in skip_invalid_values: a non-important setting whose value is rejected (BAD_ARGUMENTS or a parse error, the isParseError classification) is reset to its default and logged; any other exception, and an IMPORTANT setting, still fails. Only receiveHello opts in, so the server keeps rejecting -1 from a client (#131194). These settings are advisory for the client: the old server still applies its own profile. clickhouse-client prints the warning on stderr, like the existing unknown-setting warning.

Tests: a gtest for the read, and a test_backward_compatibility case that fails without the change. Locally against 26.10.2.103: client, remote() and cluster() connect; the server still rejects -1 from a client.

The alternative is reverting #131269, which re-opens #131194. This should follow #131269 into 26.10 (#131472) and the open 26.3/26.8/26.9 cherry-picks (#131469, #131470, #131471).


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

Version info

  • Merged into: 26.11.1.2402-master (included in 26.11 and later)
  • Backported to: 26.10.11.6, 26.9.37.3, 26.8.45.3

Since ClickHouse#131269 a `Seconds` setting rejects a negative or overflowing value,
while every supported older release accepts and stores one, and its
`TCPHandler::sendHello` sends the user's changed settings in `Hello`.
`Connection::receiveHello` read them with the same strict `BaseSettings::read`
the server uses for a client's query settings, so a client or an initiator
with ClickHouse#131269 could not connect at all to an older server whose user or
profile has e.g. `max_execution_time = -1` (`Code: 36 ... cannot be negative`).
An unknown non-important setting from the server was already only a warning.

`BaseSettings::read` gets an opt-in `skip_invalid_values`: in the
`STRINGS_WITH_FLAGS` branch the value string is read first, and if parsing
it throws `BAD_ARGUMENTS` or a parse error (`isParseError`, the same
classification `insertPostgreSQLValue` uses) for a non-important setting,
the field is reset to its default and a warning is logged. The reset is
needed because `SettingFieldNonZeroUInt64::parseFromString` assigns before it
throws. Any other exception, and an `IMPORTANT` setting (the rule the
unknown-setting branch already applies), still fail the read. Only
`Connection::receiveHello` opts in: the settings in `Hello` are advisory for
the client (the server applies its own profile to every query), while the
server's read of a client's settings must keep rejecting `-1` (ClickHouse#131194).

Tests: a gtest for the tolerant read (a rejected `Seconds` value, a zero
`NonZeroUInt64`, an unparsable `Bool`, a valid setting after them, the strict
default, an `IMPORTANT` flag, and an unknown enum name (`load_balancing`),
which still fails the tolerant read), and a `test_backward_compatibility` case
with a 25.3 node: a user with `max_execution_time = -1`, reached by the tested
client and by a tested `remote()` initiator. The test uses
`query_and_get_answer_with_error` because the client prints the warning on
stderr.

Closes ClickHouse#131506
Related ClickHouse#131269, ClickHouse#131194

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

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

Pre-publication review by an independent model (engine: codex; 4 findings over 3 rounds) plus my own cold reviews (6 nits).

# Sev Finding Verdict Evidence / action
1 ❌ A known setting sent with the CUSTOM flag is converted by accessor.setValue outside the new catch (BaseSettings.h read) DISAGREE A server writes CUSTOM only for an entry of its custom settings map, which it fills only for a name that is not a built-in there and that matches custom_settings_prefixes (shipped value SQL_). No built-in setting starts with SQL_ or custom_, so no server with the shipped config can send a CUSTOM name that this version resolves to a built-in. The cited gtest covers the client to server read, which stays strict.
2 ⚠️ The gtest never reaches the isParseError classification AGREE, fixed in this PR The block now also carries an unparsable Bool (CANNOT_PARSE_BOOL); a mutant that keeps only BAD_ARGUMENTS fails the case.
3 💡 The integration case needs the oldest tested version (25.3) to accept max_execution_time = -1 noted 25.3 never gets #131269; a later bump to a version with it fails loudly at CREATE USER, which is when the case should go.
4 💡 The warning says "Cannot parse" also for a value that parses but is rejected noted The appended exception message gives the reason.
5 ⚠️ No test proves that an error other than BAD_ARGUMENTS or a parse error still fails the tolerant read AGREE, fixed in this PR The case now also reads an unknown load_balancing name with skipping on and expects UNKNOWN_LOAD_BALANCING; a mutant that skips every error fails it.
6 💡 An enum name this version does not know is still not skipped noted Not introduced by #131269 and not measured on any release; widening the classification is a separate change.
7 ⚠️ A hostile server can repeat an invalid setting up to 65,536 times in one Hello and get one warning per entry DISAGREE The same server can answer the handshake with an Exception packet instead (receiveHello), whose message and stack trace are read up to 1 GiB each (readException), printed as is by the client and logged in full by an initiator. So the warnings give it no log volume it does not already have. A real server writes each changed setting once (BaseSettings::write), so there is one warning per invalid value in its profile.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-11:20261114-143300

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. test_backward_compatibility/test.py::test_new_client_and_initiator_with_negative_seconds_in_old_server_profile (25.3 node) fails every run on master a33e1c1 with Code: 36 ... cannot be negative. Got -1; same for clickhouse-client and remote() / cluster() against a 26.10.2.103 server whose user has max_execution_time = -1.
b Root cause explained? Connection::receiveHello parses the server's Hello settings with the strict BaseSettings::read; since #131269 a negative Seconds value throws there, and the throw aborts the handshake. An unknown setting was already only a warning.
c Fix matches root cause? Yes. Only the read of the server's advisory settings skips a value this version rejects (reset to default + warning); the server's read of a client's settings stays strict (#131194).
d Test intent preserved / new tests added? New gtest for the tolerant read and the strict default, new integration case with a 25.3 node. SecondsOnTheWireRejectNegativeAndOverflowingValues, 04058, 03000, 04201 stay green.
e Both directions demonstrated? Integration: 1 failed without the change, 2 passed with it (5/5 repeats). Mutations (pass false in receiveHello, drop the reset, always skip, ignore IMPORTANT, drop the parse-error class, skip every error code) each turn a test red.
f Fix is general across code paths? receiveHello is the only client-side reader of server settings; every Connection user (pools, hedged, remote(), Distributed, dictionaries, DatabaseRemote) goes through it. Other read callers keep the strict default.
g Fix generalizes across inputs (params/datatypes/wrappers)? Negative, overflowing (stored negative), the obsolete drain_timeout, a NonZeroUInt64 zero, an unparsable Bool, an IMPORTANT-flagged value and an unknown enum name (both still fail), a valid setting after the bad ones. Rejections are classified by BAD_ARGUMENTS or isParseError; other exceptions propagate.
h Backward compatible? (maintainer-approved exception only) Yes: no setting, default or protocol change; older servers are reachable again.
i Invariants and contracts preserved? The value string is consumed before the parse, so the stream stays aligned; a skipped field is back at its default with changed = false (NonZeroUInt64 assigns before it throws); non-value exceptions and IMPORTANT settings still fail the read.

Session id: cron:clickhouse-impl-slot-7:20261114-115200

@clickhouse-gh

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [89f9b5d]

Summary: ✅


AI Review

Summary

PR #131636, reviewed at 89f9b5d3c57e60a29ae274e153cc2254553697c5, restores native connections to older servers advertising non-important settings with values the newer client rejects. Only Connection::receiveHello enables tolerant parsing; rejected fields are reset, while query settings, IMPORTANT settings, and unrelated exceptions remain strict. No actionable findings remain after reviewing the current diff, surrounding code, regression coverage, and all prior discussion. No inline comments were posted.

Missing context / blind spots
  • ⚠️ Current-head unit and integration CI jobs were pending at review time, and runtime tests were not rerun locally. The author reports successful local settings tests and connection regression checks after the merge with master; completion of the pending CI jobs will provide independent runtime confirmation.
Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default can be tested Allows running workflows for external contributors comp-settings Settings & configuration infrastructure (server/user/query settings, profiles). labels Nov 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 89f9b5d3c with master 3c6741b7e (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 39856bd39; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

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

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai fix conflicts.

…skip-invalid-values

Resolve the conflicts with ClickHouse#131099, which removed `SettingsWriteFormat`:
`BaseSettings::read` and `Settings::read` now take only `skip_invalid_values`,
and the tolerant parse applies to the single remaining string path.

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

Copy link
Copy Markdown
Collaborator Author

Fixed in 89f9b5d by merging master. The conflict was #131099 removing SettingsWriteFormat, so read now takes only skip_invalid_values.

Re-checked on the merged build: the settings gtests pass, and a client connecting to a 26.10.2.103 server whose user has max_execution_time = -1 still fails with Code: 36 on master and connects with this PR. The server still rejects -1 sent by a client.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Questionable, but ok.

@alexey-milovidov alexey-milovidov self-assigned this Nov 15, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 16, 2026
Merged via the queue into ClickHouse:master with commit e221bba Nov 16, 2026
192 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 16, 2026
@fm4v fm4v added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Nov 19, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 19, 2026
robot-ch-test-poll2 added a commit that referenced this pull request Nov 22, 2026
Cherry pick #131636 to 26.10: Skip a setting value from the server's Hello that this version rejects instead of failing the connection
robot-clickhouse added a commit that referenced this pull request Nov 22, 2026
…lo that this version rejects instead of failing the connection
alexey-milovidov pushed a commit that referenced this pull request Nov 22, 2026
Resolve the conflicts of the cherry-pick of #131636. 26.9 still has
`SettingsWriteFormat` (master removed it in #131099), so `read` keeps its
`format` argument and takes `skip_invalid_values` after it, as in the
first commit of #131636 (669fb8d), which was written against this API.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov pushed a commit that referenced this pull request Nov 22, 2026
Resolve the conflicts of the cherry-pick of #131636. 26.8 still has
`SettingsWriteFormat` (master removed it in #131099), so `read` keeps its
`format` argument and takes `skip_invalid_values` after it, as in the
first commit of #131636 (669fb8d), which was written against this API.

The new gtest goes right after `SecondsOnTheWireRejectNegativeAndOverflowingValues`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-ch-test-poll added a commit that referenced this pull request Nov 22, 2026
Cherry pick #131636 to 26.8: Skip a setting value from the server's Hello that this version rejects instead of failing the connection
robot-clickhouse added a commit that referenced this pull request Nov 22, 2026
…o that this version rejects instead of failing the connection
robot-ch-test-poll added a commit that referenced this pull request Nov 22, 2026
Cherry pick #131636 to 26.9: Skip a setting value from the server's Hello that this version rejects instead of failing the connection
robot-clickhouse added a commit that referenced this pull request Nov 22, 2026
…o that this version rejects instead of failing the connection
alexey-milovidov added a commit that referenced this pull request Nov 22, 2026
Conflicts in `src/Client/Connection.cpp`, `src/Core/BaseSettings.h`,
`src/Core/Settings.cpp`, `src/Core/Settings.h` and
`src/Core/tests/gtest_settings.cpp` are resolved by taking the 26.3 side and
re-applying the change of #131636 on top of the 26.3 API
(`read(in, format, skip_invalid_values)`, `isParseError` from
`Processors/Formats/IRowInputFormat.h`).

Adaptation for 26.3: here `SettingFieldSeconds::parseFromString` does not
validate the value (#112757 is not on 26.3), so reading `max_execution_time = -1`
from the server's `Hello` succeeds and the client fails later, when it applies
the value as a `Field`. With `skip_invalid_values`, `BaseSettings::read` now
also re-assigns the parsed value as a `Field`, so such a value is skipped with
a warning, as on master. The strict read (the server side) is unchanged.
The gtest is adapted accordingly; master-only gtests are not carried over.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
robot-ch-test-poll2 added a commit that referenced this pull request Nov 22, 2026
Cherry pick #131636 to 26.3: Skip a setting value from the server's Hello that this version rejects instead of failing the connection
robot-clickhouse added a commit that referenced this pull request Nov 22, 2026
…o that this version rejects instead of failing the connection
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 22, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 22, 2026
Backport #131636 to 26.10: Skip a setting value from the server's Hello that this version rejects instead of failing the connection
clickhouse-gh Bot added a commit that referenced this pull request Nov 22, 2026
Backport #131636 to 26.9: Skip a setting value from the server's Hello that this version rejects instead of failing the connection
clickhouse-gh Bot added a commit that referenced this pull request Nov 22, 2026
Backport #131636 to 26.8: Skip a setting value from the server's Hello that this version rejects instead of failing the connection
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 comp-settings Settings & configuration infrastructure (server/user/query settings, profiles). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default 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.

New client refuses old server's negative Seconds in Hello; connection fails

6 participants