Le 13/03/2020 à 08:02, Kevin Zhu a écrit :
In version 2.1.3:
When config spoe engine proxys > 1, the function "srandom" will run more
than one times, it will make some engine_id duplicated, and the SPOA
is group SPOP connections by engine_id when option async is on, the
ack will reply to the wrong SPOE.
This patch should backport to 2.0 and 1.9.
Sorry, but your patch does not fix the bug.
First, for 2.x, recent changes to implement a thread-safe and process-safe PRNG
seem to make this patch useless.
For the version 1.9, the problem is not to run srandom() multiple times because
it is executed only once per process, for the first thread. But the
spoe_init_per_thread() callback function is not necessarily called for the first
thread first. So an engine ID may be generated for a thread before calling
srandom(). This way it is possible to have same ID for several threads on
different process. AFAIK, the bug should only be possible when nbproc and
nbthread are mixed.
In your patch, srandom() may be called multiple times for the same process
because the init variable may be seen to 0 by several threads. So it is possible
to reset the random seed before generating an engine ID. This way, several
threads may have the same engine ID for the same process.
Unfortunately, to fix the bug, we have to synchronize the threads to be sure
only one thread runs srandom() before generating any engine ID. So, we must have
a lock. Another solution is to call srandom() just after the fork of a process.