aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2025-09-26 15:31:32 +0200
committerAleksandr Nogikh <nogikh@google.com>2025-10-01 14:41:08 +0000
commit1bd1bc7d21be9920a31f48d2e962dc74274d216f (patch)
tree1645860e7374ab650321089f1f884c1ed8631c0a
parent12039a0e63377e86fa1b5adc3d327d6e07f23a32 (diff)
vm: use error wrapping to detect ssh connection errors
This is a much cleaner logic than string matching.
-rw-r--r--vm/qemu/qemu.go7
-rw-r--r--vm/vmimpl/util.go4
2 files changed, 6 insertions, 5 deletions
diff --git a/vm/qemu/qemu.go b/vm/qemu/qemu.go
index 6714703fe..55473a419 100644
--- a/vm/qemu/qemu.go
+++ b/vm/qemu/qemu.go
@@ -7,6 +7,7 @@ import (
"bytes"
"context"
"encoding/json"
+ "errors"
"fmt"
"io"
"net"
@@ -348,10 +349,8 @@ func (pool *Pool) Create(ctx context.Context, workdir string, index int) (vmimpl
if err == nil {
return inst, nil
}
- if strings.Contains(err.Error(), "can't ssh into the instance") {
- // If there was a boot error, immediately return it.
- // In this case, the string search below also matches against boot time output,
- // and e.g. "Device or resource busy" is quite often in there.
+ if errors.Is(err, vmimpl.ErrCantSSH) {
+ // It is most likely a boot crash, just return the error as is.
return nil, err
}
// Older qemu prints "could", newer -- "Could".
diff --git a/vm/vmimpl/util.go b/vm/vmimpl/util.go
index 729e78de6..a0e3ce841 100644
--- a/vm/vmimpl/util.go
+++ b/vm/vmimpl/util.go
@@ -58,13 +58,15 @@ func WaitForSSH(timeout time.Duration, opts SSHOptions, OS string, stop chan err
}
if time.Since(startTime) > timeout {
return &osutil.VerboseError{
- Err: fmt.Errorf("can't ssh into the instance"),
+ Err: ErrCantSSH,
Output: []byte(err.Error()),
}
}
}
}
+var ErrCantSSH = fmt.Errorf("can't ssh into the instance")
+
func SSHArgs(debug bool, sshKey string, port int, systemSSHCfg bool) []string {
return sshArgs(debug, sshKey, "-p", port, 0, systemSSHCfg)
}