Skip to content

Fix crash when lowering a workload concurrency limit below in-flight - #118836

Merged
serxa merged 3 commits into
masterfrom
semaphore-constraint-update-null-parent
Sep 12, 2026
Merged

serxa merged 3 commits into
masterfrom
semaphore-constraint-update-null-parent

Conversation

@serxa

@serxa serxa commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Linked issues

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Fixed a server crash that could happen when a WORKLOAD setting limiting concurrency (e.g. max_concurrent_queries or max_bytes_inflight) was lowered below the number of currently in-flight resource requests while the workload was active.

Description

When a workload update lowers a semaphore limit below the amount currently in flight while the node is active, SemaphoreConstraint::updateConstraints transitions active() from true to false and deactivates the node with a detach/re-attach trick:

parent->removeChild(this);
parent->attachChild(self);

removeChild(this) resets this node's own parent member to nullptr (via setParentNode(nullptr)), so the second statement re-read the now-null parent and performed a virtual call on it, crashing the server with a SIGSEGV. Only SemaphoreConstraint is affected — ThrottlerConstraint::updateConstraints has no deactivation branch.

The fix captures the parent pointer in a local before detaching and reuses it for the re-attach. updateConstraints runs on the scheduler thread, where tree mutations are serialized, so the saved pointer stays valid and the re-attach semantics are unchanged.

A regression test (SchedulerTimeSharedWorkloadNode.UpdateSemaphoreDeactivateBelowInflight) lowers a semaphore limit below the in-flight amount while the node is active; it crashes without the fix and passes with it.


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

Version info

  • Merged into: 26.9.1.1307 (included in 26.9 and later)
  • Backported to: 26.8.3.101, 26.7.7.92, 26.6.5.119, 26.3.33.68

SemaphoreConstraint::updateConstraints takes a deactivation trick when a
workload update lowers a semaphore limit (max_concurrent_queries /
max_bytes_inflight) below the currently in-flight amount while the node is
active: it calls parent->removeChild(this) followed by parent->attachChild(self).
removeChild resets this node's own `parent` member to nullptr (via
setParentNode()), so the subsequent re-read of `parent` dereferenced a null
pointer and crashed the server (SIGSEGV).

Capture the parent pointer in a local before detaching and reuse it for the
re-attach. Add a regression test that lowers a semaphore limit below the
in-flight amount while the node is active.
@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [507652b]

Summary: ✅


AI Review

Summary

This PR fixes SemaphoreConstraint::updateConstraints when a workload semaphore limit is lowered below the current in-flight usage: it now preserves the parent pointer across the detach/reattach deactivation path and cancels a stale pending activation queued under the old limit. I did not find a remaining correctness issue in the updated path, and the added regressions cover both the null-parent dereference and the stale-activation over-admission case.

Final Verdict

✅ No blocking issues found in the current diff.

LLVM Coverage Report

Measured on commit 507652b.

Metric Baseline Current Δ
Lines 89.00% 89.00% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 81.40% 81.30% -0.10%

Changed lines: Changed C/C++ lines covered: 29/29 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Sep 8, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-scheduler Workload scheduler and resource management: CPU/IO/memory scheduling, concurrency control, worklo... label Sep 8, 2026
@watson-ch

watson-ch Bot commented Sep 8, 2026

Copy link
Copy Markdown

Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/2067

Labels added:

  • v26.4-must-backport

These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels.

@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 507652b73 with master 3476b12ea (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

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

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

Job report

…phore

When updateConstraints lowers a semaphore limit below the in-flight amount it
force-deactivates the node via removeChild/attachChild. A concurrent finishRequest
may have queued an activation for the node under the old limit; left in the
EventQueue it would re-activate the semaphore under the new lower limit and admit
one request over the bound (dequeueRequest has no satisfied() gate). Cancel the
pending activation in the deactivation branch, mirroring FifoQueue when its queue
empties. Add a regression test that leaves an activation pending across the update.
@serxa
serxa marked this pull request as ready for review September 12, 2026 13:58

@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.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Sep 12, 2026
@serxa
serxa enabled auto-merge September 12, 2026 16:56
@serxa
serxa added this pull request to the merge queue Sep 12, 2026
Merged via the queue into master with commit 213c691 Sep 12, 2026
175 checks passed
@serxa
serxa deleted the semaphore-constraint-update-null-parent branch September 12, 2026 19:50
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 12, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 12, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 12, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 12, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 12, 2026
Backport #118836 to 26.8: Fix crash when lowering a workload concurrency limit below in-flight
clickhouse-gh Bot added a commit that referenced this pull request Sep 12, 2026
Backport #118836 to 26.6: Fix crash when lowering a workload concurrency limit below in-flight
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 13, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 13, 2026
Backport #118836 to 26.7: Fix crash when lowering a workload concurrency limit below in-flight
PedroTadim added a commit that referenced this pull request Sep 13, 2026
Backport #118836 to 26.3: Fix crash when lowering a workload concurrency limit below in-flight
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 18, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 18, 2026
@serxa serxa mentioned this pull request Sep 19, 2026
24 of 33 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-scheduler Workload scheduler and resource management: CPU/IO/memory scheduling, concurrency control, worklo... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix 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 v26.4-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants