Skip to content

Cherry pick #108977 to 26.3: Fix out-of-bounds crash in ObjectStorageQueueSource::FileIterator::next - #112835

Merged
robot-clickhouse-ci-1 merged 12 commits into
backport/26.3/108977from
cherrypick/26.3/108977
Aug 2, 2026
Merged

robot-clickhouse-ci-1 merged 12 commits into
backport/26.3/108977from
cherrypick/26.3/108977

Conversation

@robot-clickhouse-ci-2

Copy link
Copy Markdown
Contributor

Original pull-request #108977

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 11 commits July 21, 2026 15:05
In the unordered hash-ring batch path of FileIterator::next, file_metadatas is
resized to the batch size and populated per file. When a file in the batch is
non-processable (num_successful_objects < new_batch.size()) and the keeper
tryMulti that sets the batch as processing then fails, the else branch clears
file_metadatas. The subsequent compaction block still wrote
file_metadatas[i] = file_metadatas[batch_i] and called file_metadatas.resize()
on the now-empty vector, going out of bounds and aborting the server. The
trailing chassert(file_metadatas.empty() || ...) already documents that an empty
file_metadatas is an expected post-state.

Guard the file_metadatas compaction so it only runs when file_metadatas was not
cleared; new_batch is still compacted as before. Downstream code already handles
an empty file_metadatas (next() returns a null FileMetadataPtr).

The regression test reproduces both crash preconditions the way they occur when
several consumers share one keeper path: a real processing node is pre-created in
keeper for one batch file so the engine's own keeper multi fails against it (real
Node exists, no faked keeper response), and a small failpoint marks another file
non-processable through the same std::nullopt path the engine takes when a file
is already being processed elsewhere.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
The regression test polled ObjectStorageQueueFailedToBatchSetProcessing for an
absolute "> 0". system.events counts for the lifetime of the server process and
started_cluster is module-scoped, so an increment left by any earlier execution
in the same process satisfied the predicate immediately. The test then deleted
the keeper conflict node before the failing batch had run, and the compaction
path the fix guards was never re-entered.

Measured on a repeated run (same server process): the poll accepted a stale
value of 1 after 0.24s with a baseline of 1, instead of waiting for this table's
own failed multi. Snapshotting the counter before the materialized view is
created (nothing consumes before that) and waiting for a strict increase makes
every execution wait for its own increment: baselines advance 0, 1, 2 and the
accepted values are 1, 2, 3.

With the out-of-bounds guard reverted, the test fails on both the first and the
repeated execution, so the assertion is live in both directions.

Co-Authored-By: Claude Fable 5 <[email protected]>
The regression test injected the non-processable file by wrapping the
prepareSetProcessingRequests call in FileIterator::next with a force_skip
conditional, editing the normal code path just to reproduce the test condition.

Move the failpoint into prepareSetProcessingRequests instead, folded into the
existing "processing lock held by another consumer" branch: try_lock its result
into a local, and let the ONCE failpoint clear that local so the first file
after the failpoint is enabled takes the real std::nullopt path a file grabbed
by another table on this server would take, including its log line. The batch
loop is restored to its original auto set_processing_result = ... form.

Verified: with the out-of-bounds guard present the test passes; with the guard
reverted the server still aborts in FileIterator::next, so the failpoint
continues to exercise the num_successful_objects < batch size compaction path.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Co-Authored-By: Claude Opus 4.8 <[email protected]>
The test only reproduces the out-of-bounds path when the file skipped by the
object_storage_queue_skip_one_file_in_batch failpoint and the pre-created Keeper
processing node land in the same getCurrentBatchAndScheduleNext result. That
precondition was satisfied only because the engine default list_objects_batch_size
is 1000, which happens to exceed files_to_generate, so a change to that default
would have turned the test green without anyone noticing.

The profile event the test waits on cannot catch that: the
ObjectStorageQueueFailedToBatchSetProcessing increment sits in the else branch of
the tryMulti result, so it fires on the failed multi alone, whether or not a
non-processable file was in the same batch.

Verified with the guard reverted: pinning the batch size to 1, so the skipped file
and the conflict land in different batches, makes the test pass against a binary
that still aborts, while the pinned value fails it as intended.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Fix out-of-bounds crash in ObjectStorageQueueSource::FileIterator::next
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-critical-bugfix labels Aug 1, 2026
Resolve the `src/Common/FailPoint.cpp` conflict: 26.3 has none of master's later
`object_storage_queue_*` failpoints, so keep the release-branch list and add only
`ONCE(object_storage_queue_skip_one_file_in_batch)`, which the cherry-picked test needs.
@robot-clickhouse-ci-1
robot-clickhouse-ci-1 merged commit eb4b400 into backport/26.3/108977 Aug 2, 2026
1 check passed
@robot-clickhouse-ci-1
robot-clickhouse-ci-1 deleted the cherrypick/26.3/108977 branch August 2, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants