diff options
| author | Kris Alder <kalder@google.com> | 2022-06-23 11:29:46 -0700 |
|---|---|---|
| committer | Aleksandr Nogikh <wp32pw@gmail.com> | 2022-06-24 12:53:09 +0200 |
| commit | a371c43c33b6f901421f93b655442363c072d251 (patch) | |
| tree | 23981bfc45e7fa25ff77c1f6a536596854f48dbd /vm/adb | |
| parent | fa7cff5aa0ddedb3e9dedbd310abbc6014dd9c01 (diff) | |
vm/adb: use adb wait-for-device for inst.waitForSSH()
Instead of looping 300 times (and spamming logs) we should just use the
tooling built in to ADB to wait for the device to come up.
Diffstat (limited to 'vm/adb')
| -rw-r--r-- | vm/adb/adb.go | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/vm/adb/adb.go b/vm/adb/adb.go index 2aafb6494..4e3cfb5d5 100644 --- a/vm/adb/adb.go +++ b/vm/adb/adb.go @@ -294,11 +294,15 @@ func (inst *instance) Forward(port int) (string, error) { } func (inst *instance) adb(args ...string) ([]byte, error) { + return inst.adbWithTimeout(time.Minute, args...) +} + +func (inst *instance) adbWithTimeout(timeout time.Duration, args ...string) ([]byte, error) { if inst.debug { log.Logf(0, "executing adb %+v", args) } args = append([]string{"-s", inst.device}, args...) - out, err := osutil.RunCmd(time.Minute, "", inst.adbBin, args...) + out, err := osutil.RunCmd(timeout, "", inst.adbBin, args...) if inst.debug { log.Logf(0, "adb returned") } @@ -370,16 +374,15 @@ func (inst *instance) runScript(script string) error { } func (inst *instance) waitForSSH() error { - var err error - for i := 0; i < 300; i++ { - if !vmimpl.SleepInterruptible(time.Second) { - return fmt.Errorf("shutdown in progress") - } - if _, err = inst.adb("shell", "pwd"); err == nil { - return nil - } + if !vmimpl.SleepInterruptible(time.Second) { + return fmt.Errorf("shutdown in progress") + } + + if _, err := inst.adbWithTimeout(10*time.Minute, "wait-for-device"); err != nil { + return fmt.Errorf("instance is dead and unrepairable: %v", err) } - return fmt.Errorf("instance is dead and unrepairable: %v", err) + + return nil } func (inst *instance) checkBatteryLevel() error { |
