Skip to content

Fix stack-use-after-scope in MergeTreeIndexVectorSimilarity - #96259

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-vector-similarity-stack-use-after-scope
Feb 7, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-vector-similarity-stack-use-after-scope

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Feb 7, 2026 •

Copy link
Copy Markdown
Member

The ThreadPoolCallbackRunnerLocal runner was declared before the add_vector_to_index lambda it dispatches. During exception-driven stack unwinding, C++ destroys locals in reverse order, so the lambda was destroyed first while thread pool tasks could still be accessing it, and only then the runner's destructor waited for tasks to finish.

Fix by declaring the lambda before the runner, so the runner is destroyed first (waits for all tasks) and the lambda is destroyed second.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96252&sha=23d9de6f6f480a69f423153e6bc107063a9dcba6&name_0=PR&name_1=Stress%20test%20%28arm_asan%29
#96252

Changelog category (leave one):

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

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

Fix stack-use-after-scope in the vector similarity index.

Version info

  • Merged into: 26.2.1.374
  • Backported to: 26.1.3.24, 25.12.6.17, 25.11.9.24

The `ThreadPoolCallbackRunnerLocal` runner was declared before the
`add_vector_to_index` lambda it dispatches. During exception-driven
stack unwinding, C++ destroys locals in reverse order, so the lambda
was destroyed first while thread pool tasks could still be accessing
it, and only then the runner's destructor waited for tasks to finish.

Fix by declaring the lambda before the runner, so the runner is
destroyed first (waits for all tasks) and the lambda is destroyed
second.

https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96252&sha=23d9de6f6f480a69f423153e6bc107063a9dcba6&name_0=PR&name_1=Stress%20test%20%28arm_asan%29

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Feb 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [67a04ab]

Summary: ❌

job_name test_name status info comment
Stress test (amd_debug) failure
Logical error: Block structure mismatch in A stream: different number of columns: (STID: 0993-38e6) FAIL cidb, issue
Stress test (amd_tsan) failure
Test script failed FAIL cidb
Stress test (arm_asan) failure
Logical error: 'Unexpected return type from equals. Expected Nullable(UInt8). Got UInt8. Action: (STID: 1611-3d19) FAIL cidb
Upgrade check (amd_release) failure
Cannot start clickhouse-server FAIL cidb
Check failed failure cidb
Finish Workflow failure
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py failure

@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 Feb 7, 2026
@alexey-milovidov
alexey-milovidov merged commit dfe4970 into master Feb 7, 2026
124 of 129 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-vector-similarity-stack-use-after-scope branch February 7, 2026 06:36
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 7, 2026
@azat

azat commented Feb 7, 2026 •

Copy link
Copy Markdown
Member

#95818 is more complete (cc @Algunenano )

@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 Feb 7, 2026
robot-clickhouse added a commit that referenced this pull request Feb 7, 2026
robot-clickhouse added a commit that referenced this pull request Feb 7, 2026
robot-clickhouse added a commit that referenced this pull request Feb 7, 2026
clickhouse-gh Bot added a commit that referenced this pull request Feb 7, 2026
Backport #96259 to 26.1: Fix stack-use-after-scope in `MergeTreeIndexVectorSimilarity`
alexey-milovidov added a commit that referenced this pull request Feb 8, 2026
Backport #96259 to 25.12: Fix stack-use-after-scope in `MergeTreeIndexVectorSimilarity`
alexey-milovidov added a commit that referenced this pull request Feb 8, 2026
Backport #96259 to 25.11: Fix stack-use-after-scope in `MergeTreeIndexVectorSimilarity`
@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 Feb 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants