-
Notifications
You must be signed in to change notification settings - Fork 3.2k
FIX: Improve PRNG seeding on Windows to ensure uniqueness of generated numbers #5265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
🎉 All Contributor License Agreements have been signed. Ready to merge. |
There was a problem hiding this 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.
05abae5 to
250fa4e
Compare
…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
250fa4e to
502b08d
Compare
Closes #5263, #3929.
Fix for the pseudo-random seed on Windows. The function
rand_risn'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