Skip to content

Conversation

@antaljanosbenjamin
Copy link

Fixes #5262

@antaljanosbenjamin antaljanosbenjamin requested a review from a team as a code owner December 5, 2025 15:52
Copilot AI review requested due to automatic review settings December 5, 2025 15:52
@confluent-cla-assistant
Copy link

🎉 All Contributor License Agreements have been signed. Ready to merge.
✅ antaljanosbenjamin
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a data race condition in the rd_kafka_broker_fetch_toppars function by adding proper locking around access to the rktp_leader_epoch field. The race condition was occurring when multiple threads could simultaneously access and check the leader epoch value without synchronization.

Key Changes:

  • Added rd_kafka_toppar_lock() and rd_kafka_toppar_unlock() calls to protect concurrent access to rktp->rktp_leader_epoch

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1109 to 1112
rd_kafka_toppar_lock(rktp);
if (rktp->rktp_leader_epoch < 0 &&
rd_kafka_has_reliable_leader_epochs(rkb)) {
/* If current leader epoch is set to -1 and
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

The lock is released before writing to the buffer at line 1128 (FetchOffset), which may also access rktp fields. Verify that the fetch offset write at line 1128 doesn't require the same lock protection, or if it does, the unlock should be moved after that operation.

Copilot uses AI. Check for mistakes.
Comment on lines 1122 to +1125
rd_kafka_buf_write_i32(rkbuf,
rktp->rktp_leader_epoch);
}
rd_kafka_toppar_unlock(rktp);
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

The lock is released before writing to the buffer at line 1128 (FetchOffset), which may also access rktp fields. Verify that the fetch offset write at line 1128 doesn't require the same lock protection, or if it does, the unlock should be moved after that operation.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Datarace in rd_kafka_broker_fetch_toppars

1 participant