Skip to content

Ignore two librdkafka toppar races in TSan builds - #128742

Closed
fm4v wants to merge 1 commit into
masterfrom
tsan-ignore-librdkafka-toppar-races
Closed

fm4v wants to merge 1 commit into
masterfrom
tsan-ignore-librdkafka-toppar-races

Conversation

@fm4v

@fm4v fm4v commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

TSan reports data races inside librdkafka in test_storage_kafka on amd_tsan. The server dies and the whole module fails, most often in test_multi_consumer_quota.py::test_temporary_lock_quota_is_retained_across_rounds. Public CIDB over the last 60 days has 11 such reports, in two families:

  • 6 reports (test_temporary_lock_quota_is_retained_across_rounds on 2026-10-21, 2026-10-25, 2026-10-26 and twice on 2026-10-27, test_kafka2_dead_letter_queue_commit_on_select on 2026-09-07). The write is in rd_kafka_toppar_op_version_bump, called from rd_kafka_toppar_pause_resume or rd_kafka_toppar_fetch_stop on the librdkafka main thread under the toppar lock. The read is in rd_kafka_toppar_handle_Offset, called from rd_kafka_broker_bufq_timeout_scan on a broker thread, which reads rktp_op_version without the lock.
  • 3 reports (test_kafka_consumers_with_assignment_after_rebalance on 2026-10-23 and 2026-10-27, test_kafka_rebalance on 2026-10-29). rd_kafka_toppar_set_fetch_state (main thread, under the lock) and rd_kafka_toppar_fetch_backoff (broker thread, from rd_kafka_fetch_reply_handle_partition_error, no lock) both write rktp_ts_fetch_backoff.

Both accesses in each pair run on librdkafka's own threads. ClickHouse code shows up only in the allocation stack of the toppar (KafkaConsumer2::initializeQueues -> cppkafka::Consumer::get_partition_queue). Add the unlocked side of each pair to tests/tsan_ignorelist.txt, next to the existing rd_kafka_broker_set_nodename entry (#55629). Both functions are static and are not inlined at these call sites (they have their own frames in the reports), so they use the *name* form. Ignoring one side of a pair is enough because TSan reports a race only against a recorded access.

A third family, rd_kafka_app_polled vs rd_kafka_cgrp_handle_ConsumerGroupHeartbeat (2 reports in test_storage_kafka_sasl/test.py::test_kafka_kip848_consumer_group_protocol, both from #127757), is left alone: the heartbeat handler is large, and ignoring it would hide too much.

Changelog category (leave one):

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

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

The broker thread reads `rktp_op_version` in `rd_kafka_toppar_handle_Offset` and writes `rktp_ts_fetch_backoff` in `rd_kafka_toppar_fetch_backoff` without the toppar lock, while the `librdkafka` main thread writes them under the lock. TSan reports kill the server for the whole `test_storage_kafka` module on `amd_tsan`.
@clickhouse-gh

clickhouse-gh Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [86fc978]

Summary: ✅


AI Review

Summary

Reviewed PR #128742 at 86fc978afd638f180dda8608bc7b51c01dc54e61. It adds TSan exclusions for rd_kafka_toppar_handle_Offset and rd_kafka_toppar_fetch_backoff to suppress two existing races inside librdkafka. The pinned dependency source and historical CIDB reports corroborate both targeted accesses. No actionable findings.

Missing context / blind spots
  • ⚠️ The head's TSan builds were queued at review time, so validation with the rebuilt binary and affected Kafka tests remains pending in PR CI. No local build or test run was performed.
Final Verdict

✅ Approve. No code changes requested; normal CI validation remains pending.

@clickhouse-gh clickhouse-gh Bot added pr-ci comp-testing Test content only (no production code). labels Nov 2, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't have any suppressions.

Comment thread tests/tsan_ignorelist.txt
# `unixRandomness` without synchronization. SQLite documents the race as harmless right at the
# access ("two or more threads all trying to open databases at the same instant might all reset
# the PRNG. But multiple resets are harmless."), and the writer in `unixRandomness` runs under
# SQLite's own PRNG mutex, which the reader in `unixOpen` does not take. Two concurrent SQLite

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also bad. We should patch sqlite instead.

@fm4v fm4v closed this Nov 5, 2026
huldarchen pushed a commit to huldarchen/ClickHouse that referenced this pull request Nov 7, 2026
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
ClickHouse#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 added comp-kafka Kafka table engine: consumers and producers on librdkafka, the Kafka2 engine that keeps offsets i... and removed comp-testing Test content only (no production code). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-kafka Kafka table engine: consumers and producers on librdkafka, the Kafka2 engine that keeps offsets i... pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants