Merge pull request #9231 from UiPath/fix/clh-pid-init

clh: initialize clh pid before using it
This commit is contained in:
Alex Lyn 2024-03-12 13:43:24 +08:00 committed by GitHub
commit a31fb35e5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -708,11 +708,10 @@ func (clh *cloudHypervisor) StartVM(ctx context.Context, timeout int) error {
}
}()
pid, err := clh.launchClh()
err = clh.launchClh()
if err != nil {
return fmt.Errorf("failed to launch cloud-hypervisor: %q", err)
}
clh.state.PID = pid
bootTimeout := clh.getClhAPITimeout()
if bootTimeout < clhCreateAndBootVMMinimumTimeout {
@ -1344,11 +1343,13 @@ func (clh *cloudHypervisor) clhPath() (string, error) {
return p, err
}
func (clh *cloudHypervisor) launchClh() (int, error) {
func (clh *cloudHypervisor) launchClh() error {
clh.state.PID = -1
clhPath, err := clh.clhPath()
if err != nil {
return -1, err
return err
}
args := []string{cscAPIsocket, clh.state.apiSocket}
@ -1406,15 +1407,17 @@ func (clh *cloudHypervisor) launchClh() (int, error) {
err = utils.StartCmd(cmdHypervisor)
if err != nil {
return -1, err
return err
}
clh.state.PID = cmdHypervisor.Process.Pid
if err := clh.waitVMM(clhTimeout); err != nil {
clh.Logger().WithError(err).Warn("cloud-hypervisor init failed")
return -1, err
return err
}
return cmdHypervisor.Process.Pid, nil
return nil
}
//###########################################################################