Skip to content

Fix three librdkafka data races that abort amd_tsan Kafka tests - #129623

Merged
alexey-milovidov merged 3 commits into
masterfrom
librdkafka-toppar-races
Nov 7, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
librdkafka-toppar-races

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Data races inside librdkafka make ThreadSanitizer abort the server in Integration tests (amd_tsan, 7/8). When that happens, a whole test_storage_kafka module fails (49 tests at once in test_batch_fast.py on 2026-11-05). This happened in 6 master runs since 2026-11-02.

This bumps contrib/librdkafka to the head of the fork branch ClickHouse/v2.15.1 (7e72f589), which adds three merged fork PRs:

  • Read rktp_op_version under the toppar lock in rd_kafka_toppar_handle_Offset librdkafka#23: rd_kafka_toppar_handle_Offset read rktp_op_version without the toppar lock when the callback runs on a broker thread (the __DESTROY path). This raced rd_kafka_toppar_op_version_bump. It now snapshots the version inside the critical section the function already takes.
  • Take the toppar lock in rd_kafka_toppar_fetch_backoff librdkafka#24: rd_kafka_toppar_fetch_backoff wrote rktp_ts_fetch_backoff from broker threads without the toppar lock. This raced rd_kafka_toppar_set_fetch_state. It now takes the lock. The two callers in rd_kafka_toppar_fetch_decide already hold the lock, so they call the new rd_kafka_toppar_fetch_backoff0 instead. None of the four remaining callers of the locking wrapper holds the lock. The body already ran under this lock from rd_kafka_toppar_fetch_decide, so no new lock-order edge is introduced.
  • Do not touch the cgrp from the application thread on poll librdkafka#26: rd_kafka_app_polled no longer touches rk_cgrp on the application thread. That access raced rd_kafka_cgrp_handle_ConsumerGroupHeartbeat in test_storage_kafka_sasl/test.py::test_kafka_kip848_consumer_group_protocol. The main thread resumes heartbeats once it sees the updated rk_ts_last_poll.

This replaces the ignore-list approach of #128742. Upstream confluentinc/librdkafka master still has the toppar races. The 2.16.0 bump (#128315, fork branch ClickHouse/v2.16.0) needs the same commits.

Reports:

Related: #128742
Related: ClickHouse/librdkafka#23
Related: ClickHouse/librdkafka#24
Related: ClickHouse/librdkafka#26

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.1629-master (included in 26.11 and later)

Bump `contrib/librdkafka` to `ClickHouse/v2.15.1-toppar-races`, which is
`ClickHouse/v2.15.1` plus ClickHouse/librdkafka#23
and ClickHouse/librdkafka#24:

- `rd_kafka_toppar_handle_Offset` read `rktp_op_version` without the toppar
  lock when the callback runs on a broker thread (the `__DESTROY` path),
  racing `rd_kafka_toppar_op_version_bump`. It now snapshots the version
  inside the critical section it already takes.
- `rd_kafka_toppar_fetch_backoff` wrote `rktp_ts_fetch_backoff` from broker
  threads without the toppar lock, racing `rd_kafka_toppar_set_fetch_state`.
  It now takes the lock; the callers in `rd_kafka_toppar_fetch_decide`, which
  already hold it, use the new `rd_kafka_toppar_fetch_backoff0`.

The TSan reports kill the server, failing whole `test_storage_kafka` modules
in `Integration tests (amd_tsan, 7/8)`: 6 master runs since 2026-11-02.
This replaces the ignore-list approach of
#128742.

Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=bfafa10aac621acb9fde1bdee67d667a132ea000&name_0=MasterCI&name_1=Integration%20tests%20%28amd_tsan%2C%207%2F8%29
Report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=5c48e43bc4f46af85f720a03edf7b100367b7ba6&name_0=MasterCI&name_1=Integration%20tests%20%28amd_tsan%2C%207%2F8%29

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

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [597cade]

Summary: ✅


AI Review

Summary

PR #129623 updates contrib/librdkafka to 7e72f589 to fix three data races involving partition state and application polling. No actionable findings in the submodule bump or underlying fixes at PR head 597cade6. The focused consumer-protocol recovery test passed locally: after exceeding max.poll.interval.ms, the consumer rejoined and consumed all 100 records.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci submodule changed At least one submodule changed in this PR. labels Nov 5, 2026
ClickHouse/librdkafka#23 and
ClickHouse/librdkafka#24 are now merged into
`ClickHouse/v2.15.1`, together with
ClickHouse/librdkafka#26, which stops
`rd_kafka_app_polled` from touching `rk_cgrp` on the application thread
(a third TSan race, against `rd_kafka_cgrp_handle_ConsumerGroupHeartbeat`).
Use the branch head instead of the temporary `ClickHouse/v2.15.1-toppar-races`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov alexey-milovidov changed the title Fix two librdkafka toppar data races that abort amd_tsan Kafka tests Fix three librdkafka data races that abort amd_tsan Kafka tests Nov 5, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-external-dependencies Third-party deps updates in contrib/, vendored code, and platform base libraries. label Nov 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 597cade63 with master 47fe54453 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 27662da64; 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

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

Median compile-time ratio to the baselines is ×0.95 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -1.2 s (-6%) in total before that adjustment.

Job report

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=129623&sha=450352d7f9eda943fc6a4336356bbf4a89ab28c8&name_0=PR&name_1=La%20Casa%20Del%20Dolor%20%28amd_tsan%29 and provide a fix in a separate PR. If the fix is already in progress, link it here.

The TSan report is a data race in StorageS3Configuration::setPaths called from StorageObjectStorage::createSink during INSERT, which is unrelated to this librdkafka bump. It matches #90967; #114995 looks like the pending fix.

@groeneai

groeneai commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

This is the race fixed by #114995, so I'm not opening a separate PR.

Both sides of the report are StorageS3Configuration::setPaths (S3/Configuration.h:127) called from StorageObjectStorage::createSink (StorageObjectStorage.cpp:1095) on two DistrOutStrProc threads: two local-shard Distributed write jobs insert into the same S3 table, share its configuration, and assign its path vector at the same time. Master still has that unlocked getPaths/setPaths read-modify-write.

#114995 removes it: createSink no longer writes the list back (it appends the new key with addPath), and the path list is guarded by paths_mutex with thread-safety annotations in every configuration subclass. The same race also shows up in La Casa Del Dolor as an ASan double-free (STID 3448-4fc3) and under other TSan STIDs (3437-4705, 5233-4bfc). #114995 was approved on 2026-11-05, its CI is green, and it is mergeable.

@alexey-milovidov alexey-milovidov self-assigned this Nov 7, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 7, 2026
Merged via the queue into master with commit 45eec84 Nov 7, 2026
188 checks passed
@alexey-milovidov
alexey-milovidov deleted the librdkafka-toppar-races branch November 7, 2026 21:14
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-external-dependencies Third-party deps updates in contrib/, vendored code, and platform base libraries. pr-ci pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants