Repository navigation
Fix message loss on consumer stop and use-after-free on destruction in StorageKafka2 - #121478
Merged
alexey-milovidov merged 4 commits intoOct 20, 2026
Merged
alexey-milovidov merged 4 commits into
alexey-milovidov merged 4 commits into
Conversation
alexey-milovidov
approved these changes
Oct 18, 2026
Contributor
|
Workflow [PR], commit [f1c4c10] Summary: ✅
AI ReviewSummaryThis PR prevents interrupted Missing context / blind spots
Final Verdict✅ Approve — no code changes requested. |
Contributor
Build profile diff (arm_release)Commit See the job log for details. |
`lockTemporaryLocksLocked` returned early without logging when it reset `tmp_locks_quota` to zero (no available partitions, or a replica without locks). `test_temporary_lock_quota_is_retained_across_rounds` reads that log line, so under fluctuating availability the old 1, 0, 1, 0, ... pattern looked like consecutive non-zero rounds and the test could pass with the original faulty condition. Now every round logs the resulting quota. Co-Authored-By: Claude Opus 5.5 <[email protected]>
vitlibar
pushed a commit
to ilejn/ClickHouse
that referenced
this pull request
Oct 22, 2026
The test from ClickHouse#121478 fails in `Integration tests (arm_binary, 2/4)` with "No consumer kept a non-zero temporary-lock quota for 4 consecutive rounds" (6 failures on 5 unrelated PRs, none on master or amd). The four `kafka_tmp_r*` tables share one server and one schedule, so their slow-path rounds fire together. Each round releases its temporary locks before `get_metadata`, which takes 150-560 ms on that runner, so every round re-contests the three leftover partitions: the first reader grows its quota to 2, the second takes 1, the others drop to 0, and each quota cycles 1, 2, 0. `lockTemporaryLocksLocked` behaves as specified (all leftovers are taken in every round); only the threshold of 4 assumed non-overlapping rounds. Lower the threshold to 2. The old inverted shrink condition reset a quota of 1 to 0 in the next round, so it can never produce two consecutive non-zero quotas, and the test still separates the two behaviours. All six recorded CI failures already contain a run of 2. Locally 10 separate runs pass, and with the old condition restored in `KeeperHandlingConsumer.cpp` 3 of 3 runs fail with every quota alternating 1, 0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed StorageKafka2 skipping messages when a consumer is stopped mid-batch, a possible use-after-free when such a table is dropped without a shutdown, and partitions outside the permanent locks being consumed only every other round.
Description
Message loss when a consumer is stopped mid-batch.
KafkaConsumer2::consumediscards the messages it has already pulled from the partition queue once it
observes the stop, but the Kafka position has already moved past them. The batch
that was being assembled still had
consumed_messages > 0, so afterfailed_poll_attemptstripped the message sink,pollreturned anOffsetGuardand the committed offset advanced past messages that were never inserted. Nothing
rewound the consumer afterwards, because
prepareToPollkeeps an existingassignment for
LOCKS_REFRESH_POLLSrounds.resetIfStoppednow drops theinterrupted batch (as
StorageKafkahas always done incleanUnprocessed), andpolldiscards the batch and rewinds to the committed offsets instead of handingout a guard.
Use-after-free when the storage is destroyed without a shutdown. The
librdkafkainterceptors installed byKafkaConfigLoadercapturethisanddereference it from
rdKafkaOnThreadExitwhen a broker thread exits.thread_statuses_mutexis declared afterconsumers, so it is destroyed first,and a storage that was started but never shut down destroyed its consumers after
that mutex was already gone. The destructor now falls back to
shutdown, the sameway
StorageKafkadoes.Temporary lock quota could never be held. The shrink condition in
lockTemporaryLocksLockedwasquota > 0 && quota <= available, the inverse ofwhat its comment describes. Reaching that code guarantees
available >= 1, so aquota of 1 always matched and was pushed straight back to 0: the quota alternated
1, 0, 1, 0, ... and a consumer held a temporary lock only every other round, with
every reacquisition moving the partition to another replica and rewinding it. The
leftover partitions that permanent locks cannot cover (
P mod R) were thereforeconsumed about half the time.
Workflow [PR]
Sync PR [sync-upstream/pr/121478]
Version info
26.11.1.265-master(included in26.11and later)