Fix locking error in WSL machine rm -f

Fixed a bug where `podman machine rm -f` would cause a deadlock when
running with WSL.

The deadlock is caused by the Remove() function calling the Stop()
function after Remove() locks the VM. Stop() also has a lock call, which
fails and deadlocks because Remove() already claimed lock. Fix this by
moving the stop call before the lock

[NO NEW TESTS NEEDED]

Signed-off-by: Ashley Cui <acui@redhat.com>
This commit is contained in:
Ashley Cui
2023-11-29 16:09:12 -05:00
parent 5da1790a28
commit 42ea211211

View File

@ -1591,9 +1591,6 @@ func readWinProxyTid(v *MachineVM) (uint32, uint32, string, error) {
func (v *MachineVM) Remove(name string, opts machine.RemoveOptions) (string, func() error, error) {
var files []string
v.lock.Lock()
defer v.lock.Unlock()
if v.isRunning() {
if !opts.Force {
return "", nil, &machine.ErrVMRunningCannotDestroyed{Name: v.Name}
@ -1603,6 +1600,9 @@ func (v *MachineVM) Remove(name string, opts machine.RemoveOptions) (string, fun
}
}
v.lock.Lock()
defer v.lock.Unlock()
// Collect all the files that need to be destroyed
if !opts.SaveKeys {
files = append(files, v.IdentityPath, v.IdentityPath+".pub")