double check the state wasn't created in the short time prior to grabbing the lock

This commit is contained in:
Sean Teeling 2020-10-14 20:25:41 -07:00
parent 7d6ec431d2
commit 8980b6dc9e
1 changed files with 18 additions and 9 deletions

View File

@ -118,19 +118,28 @@ func (b *Backend) StateMgr(name string) (statemgr.Full, error) {
return parent
}
// If we have no state, we have to create an empty state
if err := stateMgr.WriteState(states.NewState()); err != nil {
err = lockUnlock(err)
return nil, err
}
if err := stateMgr.PersistState(); err != nil {
// Grab the value
if err := stateMgr.RefreshState(); err != nil {
err = lockUnlock(err)
return nil, err
}
//if this isn't the default state name, we need to create the object so
//it's listed by States.
if v := stateMgr.State(); v == nil {
// If we have no state, we have to create an empty state
if err := stateMgr.WriteState(states.NewState()); err != nil {
err = lockUnlock(err)
return nil, err
}
if err := stateMgr.PersistState(); err != nil {
err = lockUnlock(err)
return nil, err
}
// Unlock, the state should now be initialized
if err := lockUnlock(nil); err != nil {
return nil, err
// Unlock, the state should now be initialized
if err := lockUnlock(nil); err != nil {
return nil, err
}
}
}