Repository navigation
Conversation
… callback fires When `DROP TABLE` sets `shutdown_called` concurrently with a naturally completing pipeline, the offset commit was incorrectly skipped because the check at line 738 tested `shutdown_called` (a global flag) rather than whether the pipeline was actually cancelled. The cancel callback polls every 100ms. If the pipeline finishes in the sub-millisecond window between writing a block and the next callback poll, the data is fully written to MergeTree but `shutdown_called` is already true, so the commit is skipped. On table recreation the consumer resumes from the last committed offset, re-reading messages that were already written — causing duplicates. Track whether the cancel callback actually fired (`cancelled` flag) and only skip the commit when the pipeline was truly interrupted. Regression introduced by c964e8e. Relevant logs: 2026.03.29 18:12:38.213836 [ 932 ] {} <Trace> StorageKafka (test.kafka_QRMOCX): Polled batch of 100 messages. Offsets position: [blockold[0:1600]] 2026.03.29 18:12:38.219505 [ 932 ] {} <Test> DedupInfo: Clone DeduplicationInfo 2039 from instance_id: 2038, sync, enabled, level SOURCE, rows/tokens 100/1, in block: rows/cols 0/10, tokens: 1:[data-hash<14668832234726696155_13389564701822897784>/source-id-empty/source-number-0::100], visited views: 1:[<empty>], retried view id: <empty>, original block id: <empty>, data_hashes: 14668832234726696155_13389564701822897784, unification_stage COMPATIBLE_DOUBLE_HASHES 2026.03.29 18:12:38.226820 [ 16 ] {d4bbd5c9-d59a-4b7e-863d-f2470caa7363} <Debug> executeQuery: (from 172.16.3.1:55538) (query 1, line 1) DROP TABLE test.kafka_QRMOCX SYNC (stage: Complete) 2026.03.29 18:12:47.939941 [ 634 ] {} <Trace> StorageKafka (test.kafka_QRMOCX): Polled batch of 100 messages. Offsets position: [blockold[0:1600]] 2026.03.29 18:12:47.943600 [ 634 ] {} <Test> DedupInfo: Clone DeduplicationInfo 2057 from instance_id: 2056, sync, enabled, level SOURCE, rows/tokens 100/1, in block: rows/cols 0/10, tokens: 1:[data-hash<14668832234726696155_13389564701822897784>/source-id-empty/source-number-0::100], visited views: 1:[<empty>], retried view id: <empty>, original block id: <empty>, data_hashes: 14668832234726696155_13389564701822897784, unification_stage COMPATIBLE_DOUBLE_HASHES CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101092&sha=246d165cac385dac5d10b74e71cddf422fec5a5e&name_0=PR&name_1=Integration+tests+%28amd_tsan%2C+2%2F6%29 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [5c2e74e] Summary: ❌
AI ReviewSummaryThis PR fixes a real Kafka offset-commit race by switching the commit guard from global Findings
Tests
ClickHouse Rules
Final Verdict
|
| { | ||
| if (shutdown_called.load()) | ||
| { | ||
| cancelled = true; |
There was a problem hiding this comment.
There is still a race window where cancelled can become true even though the pipeline has already completed successfully.
Concrete trace with interactive_timeout_ms = 100:
- In
CompletedPipelineExecutor::execute,tryWait(100)returnsfalseat line 89 (timeout). - Immediately after that, worker thread finishes, sets
is_finished = trueandfinish_event.set()at lines 50-51. - Main thread then executes this callback, sees
shutdown_called == true, setscancelled = true, and callscancel()at lines 92-95. streamToViewsreturns,cancelledstaystrue, and we skipsource->commit()even though data was fully written.
So this can still reproduce duplicate re-reads in a narrow timing window. Please gate cancelled = true on confirmed interruption, not on "callback observed shutdown". One way is to move this state into CompletedPipelineExecutor (e.g. expose whether cancel actually won before finish) and use that result here.
LLVM Coverage Report
Changed lines: 100.00% (21/21) · Uncovered code |
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
| /// `shutdown_called`, because the pipeline may have completed naturally before | ||
| /// the cancel callback had a chance to fire. In that case the data was fully | ||
| /// written and offsets must be committed to avoid duplicates on restart. | ||
| if (!cancelled) |
There was a problem hiding this comment.
DROP TABLE/pipeline-finish interleaving described in the PR. Without such a test, this path is likely to regress again.
Please add an integration test that exercises shutdown during a batch where data can be fully written before cancellation polling observes shutdown_called, and assert offsets are committed (no duplicate reread after recreate).
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix Kafka offset commit skipped when pipeline completes before cancel callback fires
When
DROP TABLEsetsshutdown_calledconcurrently with a naturally completing pipeline, the offset commit was incorrectly skipped because the check at line 738 testedshutdown_called(a global flag) rather than whether the pipeline was actually cancelled.The cancel callback polls every 100ms. If the pipeline finishes in the sub-millisecond window between writing a block and the next callback poll, the data is fully written to MergeTree but
shutdown_calledis already true, so the commit is skipped. On table recreation the consumer resumes from the last committed offset, re-reading messages that were already written — causing duplicates.Track whether the cancel callback actually fired (
cancelledflag) and only skip the commit when the pipeline was truly interrupted.Regression introduced by #100388 @ c964e8e
Relevant logs:
CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=101092&sha=246d165cac385dac5d10b74e71cddf422fec5a5e&name_0=PR&name_1=Integration+tests+%28amd_tsan%2C+2%2F6%29
#101092