Repository navigation
Description
Description
When using the new GroupProtocol (KIP-848) on Windows, initializing multiple consumer instances within the same process may results in identical Member IDs (UUIDs) if they are created in rapid succession.
This causes the Group Coordinator to treat multiple consumers as the same member, preventing them from joining the group or receiving assignments correctly.
Environment
librdkafka: v2.12.0
OS: Windows (x64)
Kafka: 4.0.1
Wrapper: confluent-kafka-dotnet v2.12.0
Reproduction Steps
Configure a client with group.protocol=consumer (KIP-848) and a shared group.id.
In a single process, instantiate two or more Consumer instances immediately one after another (within the same second).
Subscribe to different topics for each consumer.
Result: Debug logs showed that all instances generated the exact same member.id, and only one consumer was able to successfully subscribe to its topics.
Root Cause Analysis
KIP-848: The Next Generation of the Consumer Rebalance Protocol
KIP-1082 Require Client-Generated IDs over the ConsumerGroupHeartbeat RPC
The issue stems from the PRNG seeding logic in the platform abstraction layer for Windows.
On Windows, librdkafka appears to fall back to the standard C rand() since rand_r() is unavailable.
Lines 35 to 62 in 477eb2e
| int rd_jitter(int low, int high) { | |
| int rand_num; | |
| #if HAVE_RAND_R | |
| static RD_TLS unsigned int seed = 0; | |
| /* Initial seed with time+thread id */ | |
| if (unlikely(seed == 0)) { | |
| struct timeval tv; | |
| rd_gettimeofday(&tv, NULL); | |
| seed = (unsigned int)(tv.tv_usec); | |
| seed ^= (unsigned int)(intptr_t)thrd_current(); | |
| /* When many threads are created at the same time and the | |
| * thread id is different only by a few bits it's possible that | |
| * `rand_r`, that is initially multiplying by `1103515245`, | |
| * truncates the variable bits and uses the same seed for | |
| * different threads. By applying `murmur2` we ensure that seed | |
| * variability is distributed across various bits at different | |
| * positions. */ | |
| seed = (unsigned int)rd_murmur2(&seed, sizeof(seed)); | |
| } | |
| rand_num = rand_r(&seed); | |
| #else | |
| rand_num = rand(); | |
| #endif | |
| return (low + (rand_num % ((high - low) + 1))); | |
| } |
When multiple instances are created in the same second, resulting in an identical sequence of random numbers for UUID generation.
Activity