mirror of
https://github.com/codership/wsrep-lib.git
synced 2025-06-13 04:01:32 +03:00
Fixed race condition in checking init_initialized on prim view
Flag init_initialized_ must be checked before changing the state to s_initializing in on_primary_view() in order to avoid race between main thread and applier thread. Otherwise it is possible that main thread gains control after setting state to initializing and changes the flag init_initialized_ to true before the check is done in on_primary_view().
This commit is contained in:
@ -705,8 +705,17 @@ void wsrep::server_state::on_primary_view(
|
||||
if (state_ == s_connected)
|
||||
{
|
||||
state(lock, s_joiner);
|
||||
// We need to assign init_initialized_ here to local
|
||||
// variable. If the value here was false, we need to skip
|
||||
// the initializing -> initialized -> joined state cycle
|
||||
// below. However, if we don't assign the value to
|
||||
// local, it is possible that the main thread gets control
|
||||
// between changing the state to initializing and checking
|
||||
// initialized flag, which may cause the initialzing -> initialized
|
||||
// state change to be executed even if it should not be.
|
||||
const bool was_initialized(init_initialized_);
|
||||
state(lock, s_initializing);
|
||||
if (init_initialized_)
|
||||
if (was_initialized)
|
||||
{
|
||||
// If server side has already been initialized,
|
||||
// skip directly to s_joined.
|
||||
|
Reference in New Issue
Block a user