From 1dfd3d3d12cbc073a8d6bc705c768fb48bf1b54d Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 13 Mar 2024 14:17:43 +0100 Subject: [PATCH] pkg/machine: refresh config after we hold lock Currently we first read the conf and then lock, this is racy because while we wait for the lock another process might change the state so the only way to have the actual current state is to read the file while holding the lock. Signed-off-by: Paul Holzinger --- pkg/machine/shim/host.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/machine/shim/host.go b/pkg/machine/shim/host.go index e2481772c3..1080874619 100644 --- a/pkg/machine/shim/host.go +++ b/pkg/machine/shim/host.go @@ -323,6 +323,9 @@ func Stop(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDef // an error. so putting in one place instead of sprinkling all over. mc.Lock() defer mc.Unlock() + if err := mc.Refresh(); err != nil { + return fmt.Errorf("reload config: %w", err) + } return stopLocked(mc, mp, dirs, hardStop) } @@ -377,6 +380,9 @@ func Start(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDe mc.Lock() defer mc.Unlock() + if err := mc.Refresh(); err != nil { + return fmt.Errorf("reload config: %w", err) + } // Set starting to true mc.Starting = true @@ -538,6 +544,9 @@ func Set(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, opts machineDefin func Remove(mc *vmconfigs.MachineConfig, mp vmconfigs.VMProvider, dirs *machineDefine.MachineDirs, opts machine.RemoveOptions) error { mc.Lock() defer mc.Unlock() + if err := mc.Refresh(); err != nil { + return fmt.Errorf("reload config: %w", err) + } state, err := mp.State(mc, false) if err != nil {