Skip to content

Disable zero-length interval quotas - #110846

Merged
PedroTadim merged 3 commits into
masterfrom
fix-quotas
Jul 18, 2026
Merged

PedroTadim merged 3 commits into
masterfrom
fix-quotas

Conversation

@PedroTadim

@PedroTadim PedroTadim commented Jul 17, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (changelog entry is required)

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

Fix a server crash (integer division by zero) when a quota with a zero-length interval (for example CREATE QUOTA q FOR INTERVAL 0 SECOND MAX queries = 1000) was consumed. A non-positive quota interval duration is now rejected at quota creation.

Description

Found by the fuzzer (STID 4141-5b13, Stress test (arm_asan_ubsan, s3), PR #110228, sha d463af4): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110228&sha=d463af42c39ba64e89709493b3e9aa2f0393e22f&name_0=PR&name_1=Stress%20test%20%28arm_asan_ubsan%2C%20s3%29

Root cause: EnabledQuota::Interval::getEndOfInterval computes (current_time - end + duration) / duration. With a zero-length interval duration == 0, so consuming the quota divides by zero. In debug/UBSan builds this is reported as UB at libcxx/include/__chrono/duration.h; in release builds it is a real SIGFPE (signal 8, integer divide by zero) that terminates the server.

Repro:

CREATE QUOTA IF NOT EXISTS q_zero FOR INTERVAL 0 SECOND MAX queries = 1000 TO default;
SELECT 1; -- server crashes with SIGFPE

Fix: reject a non-positive interval duration at quota creation in updateQuotaFromQueryImpl, which is the single validation point used by both the SQL DDL path and the on-disk reload path (AccessEntityIO). The XML users-config path already skips non-positive durations. A fractional interval that rounds down to zero seconds (e.g. INTERVAL 0.4 SECOND) is rejected too, since it hits the same code path.

Closes #110343
Closes #110860

Version info

  • Merged into: 26.7.1.1146 (included in 26.7 and later)

@clickhouse-gh

clickhouse-gh Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [055ecab]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_tsan, 3/6) FAIL
test_replicated_database/test.py::test_replicated_table_structure_alter FAIL cidb, issue ISSUE EXISTS

AI Review

Summary

This PR rejects non-positive quota intervals to stop the divide-by-zero path in quota consumption, and it adds a stateless regression test for CREATE QUOTA ... FOR INTERVAL 0 SECOND. The create-time validation is reasonable, but wiring the same rejection into access-entity deserialization makes previously persisted zero-interval quotas unreadable after upgrade, so I would not merge this as-is.

PR Metadata

Changelog category is not correct for the actual change. This is a user-visible server bug fix, not a CI-only improvement, so it should be:

### Changelog category (leave one):
- Bug Fix (changelog entry is required)

The Changelog entry itself is specific and user-readable, and it already explains the user-visible impact well enough once the category is corrected.

Findings

❌ Blockers

  • [src/Interpreters/Access/InterpreterCreateQuotaQuery.cpp:80] The new validation also runs while deserializing persisted access entities via AccessEntityIO, not just on fresh DDL. QuotaCache::ensureAllQuotasRead then eagerly tryReads every quota before any session can build its quota state, so one legacy ATTACH QUOTA ... FOR INTERVAL 0 SECOND ... file from an older release will now make quota initialization fail for every user/session. That is a backward-incompatible change on existing data rather than just a create-time fix. Suggested fix: keep rejecting non-positive intervals on new CREATE/ALTER, but make the reload path tolerate legacy bad intervals or bad quota files with a warning, similar to how UsersConfigParser already skips non-positive durations.
Final Verdict

Status: ❌ Block

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Jul 17, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.00% 86.00% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 78.10% 78.20% +0.10%

Changed lines: Changed C/C++ lines covered: 12/14 (85.71%) · Uncovered code

Full report · Diff report

@PedroTadim

Copy link
Copy Markdown
Member Author

No one sets 0 interval quotas, so this is not a concern for upgrades

@PedroTadim
PedroTadim added this pull request to the merge queue Jul 18, 2026
Merged via the queue into master with commit 8f67679 Jul 18, 2026
176 of 178 checks passed
@PedroTadim
PedroTadim deleted the fix-quotas branch July 18, 2026 10:07
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 18, 2026
alexey-milovidov added a commit that referenced this pull request Jul 18, 2026
Pulls in the quota zero-length-interval SIGFPE fix (#110846) so the
unrelated Stress amd_tsan flake clears on the next CI run.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
alexey-milovidov added a commit that referenced this pull request Jul 18, 2026
Pull in #110846 ("Disable zero-length interval quotas", merged into
master as 6a09288), which fixes the SIGFPE in
`EnabledQuota::Interval::getEndOfInterval` that failed the Stress test
(amd_debug) job on this PR (tracked issue #110860, now closed). The
crash was unrelated to framing formats; merging clears that red on the
next CI run.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
pull Bot pushed a commit to Mu-L/ClickHouse that referenced this pull request Jul 19, 2026
The test created a query quota with `TO default`. A quota is a server-global
entity, and in stress and parallel runs all stateless tests execute
concurrently against the same server as the `default` user, so the quota on
`default` was consumed by every concurrent query, exhausted its limit, and made
the server reject subsequent queries with `QUOTA_EXCEEDED` — eventually taking
the whole server down (`Server is not responding`).

The interval is validated at CREATE time in `InterpreterCreateQuotaQuery`,
independent of the `TO` assignment, so the quota does not need to be assigned to
anyone for the test to exercise the `BAD_ARGUMENTS` rejection. Drop the
`TO default` clause so the test no longer touches the shared `default` user; the
reference output (`BAD_ARGUMENTS` / `BAD_ARGUMENTS` / `ok`) is unchanged.

Surfaced on the `Stress test (amd_msan)` job of
ClickHouse#106215
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106215&sha=0b2a2b671abe9df2dae40253fb8fafacaf699575&name_0=PR&name_1=Stress%20test%20%28amd_msan%29

Caused by: ClickHouse#110846

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The test created a query quota with `TO default`. A quota is a server-global
entity, and in stress and parallel runs all stateless tests execute
concurrently against the same server as the `default` user, so the quota on
`default` was consumed by every concurrent query, exhausted its limit, and made
the server reject subsequent queries with `QUOTA_EXCEEDED` — eventually taking
the whole server down (`Server is not responding`).

The interval is validated at CREATE time in `InterpreterCreateQuotaQuery`,
independent of the `TO` assignment, so the quota does not need to be assigned to
anyone for the test to exercise the `BAD_ARGUMENTS` rejection. Drop the
`TO default` clause so the test no longer touches the shared `default` user; the
reference output (`BAD_ARGUMENTS` / `BAD_ARGUMENTS` / `ok`) is unchanged.

Surfaced on the `Stress test (amd_msan)` job of
ClickHouse#106215
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106215&sha=0b2a2b671abe9df2dae40253fb8fafacaf699575&name_0=PR&name_1=Stress%20test%20%28amd_msan%29

Caused by: ClickHouse#110846

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Received signal 8 (signal sent by pid 1739988839 from user 21971) (STID: 4141-584d) UndefinedBehaviorSanitizer: undefined behavior (STID: 4141-5b13)

2 participants