fix(publicip): lock settings during entire update
- to prevent race conditions when data is cleared when vpn goes down
This commit is contained in:
@@ -8,8 +8,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (l *Loop) update(partialUpdate settings.PublicIP) (err error) {
|
func (l *Loop) update(partialUpdate settings.PublicIP) (err error) {
|
||||||
// No need to lock the mutex since it can only be written
|
l.settingsMutex.Lock()
|
||||||
// in the code below in this goroutine.
|
defer l.settingsMutex.Unlock()
|
||||||
|
|
||||||
updatedSettings, err := l.settings.UpdateWith(partialUpdate)
|
updatedSettings, err := l.settings.UpdateWith(partialUpdate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -36,9 +37,7 @@ func (l *Loop) update(partialUpdate settings.PublicIP) (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
l.settingsMutex.Lock()
|
|
||||||
l.settings = updatedSettings
|
l.settings = updatedSettings
|
||||||
l.settingsMutex.Unlock()
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user