1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix for lack of syncromization in daemon/update.go

Signed-off-by: dmytro.iakovliev <dmytro.iakovliev@zodiacsystems.com>
(cherry picked from commit 58825ffc32)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
dmytro.iakovliev 2021-02-08 12:57:00 +02:00 committed by Sebastiaan van Stijn
parent 22ff2ed34b
commit b2684c1857
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -42,20 +42,25 @@ func (daemon *Daemon) update(name string, hostConfig *container.HostConfig) erro
restoreConfig := false
backupHostConfig := *ctr.HostConfig
defer func() {
if restoreConfig {
ctr.Lock()
ctr.HostConfig = &backupHostConfig
ctr.CheckpointTo(daemon.containersReplica)
if !ctr.RemovalInProgress && !ctr.Dead {
ctr.HostConfig = &backupHostConfig
ctr.CheckpointTo(daemon.containersReplica)
}
ctr.Unlock()
}
}()
ctr.Lock()
if ctr.RemovalInProgress || ctr.Dead {
ctr.Unlock()
return errCannotUpdate(ctr.ID, fmt.Errorf("container is marked for removal and cannot be \"update\""))
}
ctr.Lock()
if err := ctr.UpdateContainer(hostConfig); err != nil {
restoreConfig = true
ctr.Unlock()
@ -66,6 +71,7 @@ func (daemon *Daemon) update(name string, hostConfig *container.HostConfig) erro
ctr.Unlock()
return errCannotUpdate(ctr.ID, err)
}
ctr.Unlock()
// if Restart Policy changed, we need to update container monitor