Skip to content

Conversation

@emasab
Copy link
Contributor

@emasab emasab commented Dec 4, 2025

Closes #5263, #3929.

Fix for the pseudo-random seed on Windows. The function rand_r isn't present on Windows and the global seed wasn't based on the current microseconds and thread id. Also it wasn't called on every thread as required on this platform but only once per process. The fix allows on this platform the uniqueness of client side member id generation in next-generation consumer group protocol.
Happening since 1.x

@emasab emasab requested a review from a team as a code owner December 4, 2025 17:39
Copilot AI review requested due to automatic review settings December 4, 2025 17:39
@confluent-cla-assistant
Copy link

🎉 All Contributor License Agreements have been signed. Ready to merge.
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 pseudo-random number generator (PRNG) seeding issues on Windows to ensure unique member ID generation in the next-generation consumer group protocol. The core problem was that Windows lacks rand_r() and requires per-thread seeding with srand(), but the previous implementation only seeded once per process and didn't incorporate thread IDs or microseconds properly.

Key Changes:

  • Introduced thrd_current_id() helper function to consistently retrieve thread IDs across platforms
  • Replaced single process-wide PRNG seeding with per-thread seeding on Windows (thread-local once_flag)
  • Enhanced seed generation to include microseconds, thread ID, and murmur2 hash for better entropy distribution

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/tinycthread_extra.h Added declaration for new thrd_current_id() helper function
src/tinycthread_extra.c Implemented thrd_current_id() with platform-specific handling for Windows vs POSIX
src/rdrand.c Updated to use new thrd_current_id() helper instead of casting thrd_current()
src/rdkafka_ssl.c Refactored to use new thrd_current_id() helper, removing duplicated platform-specific code
src/rdkafka_mock.c Added PRNG seeding call in mock cluster thread initialization
src/rdkafka_int.h Added declaration for new rd_kafka_thread_srand() function
src/rdkafka_broker.c Added PRNG seeding call in broker thread initialization
src/rdkafka_background.c Added PRNG seeding call in background thread initialization
src/rdkafka.c Major refactoring: replaced global seeding with thread-aware seeding logic, made once_flag thread-local on Windows, improved seed entropy with murmur2 hash
CHANGELOG.md Documented the Windows PRNG seeding fix

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

…d numbers.

Fix for the pseudo-random seed on Windows. The function `rand_r` isn't present on Windows and the global seed wasn't based on the current microseconds and thread id. Also it wasn't called on every thread as required on this platform but only once per process. The fix allows on this platform the uniqueness of client side member id generation in next-generation consumer group protocol.
Happening since 1.x
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.

Member ID collision for multiple consumers in same process (KIP-848 / on Windows)

2 participants