From 99f68898c0f1c4564cebd6a3ee18418c74684403 Mon Sep 17 00:00:00 2001 From: Brent Baude Date: Wed, 22 Jun 2022 14:17:30 -0500 Subject: reveal machine error, ignore false state This PR covers two edge cases discovered by fiddling with machine manually. It is possible (like after a manual cleanup of a machine) that a leftover qemu socket file can indicate the prescense of a machine running. Also, reveal the error of a Exec.Command by wrapping the generic error around what was in stderr. [NO NEW TESTS NEEDED] Signed-off-by: Brent Baude --- pkg/machine/qemu/machine.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'pkg/machine/qemu') diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go index 5094345ea..f7ef52573 100644 --- a/pkg/machine/qemu/machine.go +++ b/pkg/machine/qemu/machine.go @@ -930,7 +930,12 @@ func (v *MachineVM) State(bypass bool) (machine.Status, error) { } monitor, err := qmp.NewSocketMonitor(v.QMPMonitor.Network, v.QMPMonitor.Address.GetPath(), v.QMPMonitor.Timeout) if err != nil { - // FIXME: this error should probably be returned + // If an improper cleanup was done and the socketmonitor was not deleted, + // it can appear as though the machine state is not stopped. Check for ECONNREFUSED + // almost assures us that the vm is stopped. + if errors.Is(err, syscall.ECONNREFUSED) { + return machine.Stopped, nil + } return "", err } if err := monitor.Connect(); err != nil { -- cgit v1.2.3-54-g00ecf