Workaround connection hangups in start/stop racing

Signed-off-by: Jason T. Greene <jason.greene@redhat.com>
This commit is contained in:
Brent Baude
2024-02-11 12:54:26 -06:00
committed by Jason T. Greene
parent 09b86e26d1
commit bb7d8fdc41

View File

@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"io/fs"
"os"
"os/exec"
@ -266,6 +267,22 @@ func (q *QEMUStubber) State(mc *vmconfigs.MachineConfig, bypass bool) (define.St
return "", err
}
if err := monitor.Connect(); err != nil {
// There is a case where if we stop the same vm (from running) two
// consecutive times we can get an econnreset when trying to get the
// state
if errors.Is(err, syscall.ECONNRESET) {
// try again
logrus.Debug("received ECCONNRESET from QEMU monitor; trying again")
secondTry := monitor.Connect()
if errors.Is(secondTry, io.EOF) {
return define.Stopped, nil
}
if secondTry != nil {
logrus.Debugf("second attempt to connect to QEMU monitor failed")
return "", secondTry
}
}
return "", err
}
defer func() {