Skip to content

Commit 1aa0fcf

Browse files
eliasnaurbradfitz
authored andcommitted
misc/android: serialize adb commands on android emulators
Android emulator builders are soon to join the trybot set. To avoid flaky runs, work around a longstanding adb bug where concurrent adb commands sometimes fail. I haven't seen the problem on actual devices until recently. It seems that the recently added "adb wait-for-device" can introduce flakyness with errors such as: adb: error: failed to get feature set: protocol fault (couldn't read status): Connection reset by peer Instead of working around that, give up and serialize use of adb everywhere. Fixes #23795 Updates #23824 Change-Id: If347c9981fa32ff8a1e14b7454f122ef682450a6 Reviewed-on: https://go-review.googlesource.com/c/163625 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent e3d99a3 commit 1aa0fcf

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

misc/android/go_android_exec.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ func main() {
6060
log.SetFlags(0)
6161
log.SetPrefix("go_android_exec: ")
6262

63+
// Concurrent use of adb is flaky, so serialize adb commands.
64+
// See https://github.com/golang/go/issues/23795 or
65+
// https://issuetracker.google.com/issues/73230216.
66+
lockPath := filepath.Join(os.TempDir(), "go_android_exec-adb-lock")
67+
lock, err := os.OpenFile(lockPath, os.O_CREATE|os.O_RDWR, 0666)
68+
if err != nil {
69+
log.Fatal(err)
70+
}
71+
defer lock.Close()
72+
if err := syscall.Flock(int(lock.Fd()), syscall.LOCK_EX); err != nil {
73+
log.Fatal(err)
74+
}
75+
6376
// In case we're booting a device or emulator alongside androidtest.bash
6477
// wait for it to be ready. adb wait-for-device is not enough, we have to
6578
// wait for sys.boot_completed.
@@ -87,15 +100,7 @@ func main() {
87100
// E.g. template.test from the {html,text}/template packages.
88101
binName := fmt.Sprintf("%s-%d", filepath.Base(os.Args[1]), os.Getpid())
89102
deviceBin := fmt.Sprintf("%s/%s", deviceGotmp, binName)
90-
91-
// The push of the binary happens in parallel with other tests.
92-
// Unfortunately, a simultaneous call to adb shell hold open
93-
// file descriptors, so it is necessary to push then move to
94-
// avoid a "text file busy" error on execution.
95-
// https://code.google.com/p/android/issues/detail?id=65857
96-
run("push", os.Args[1], deviceBin+"-tmp")
97-
run("shell", "cp '"+deviceBin+"-tmp' '"+deviceBin+"'")
98-
run("shell", "rm '"+deviceBin+"-tmp'")
103+
run("push", os.Args[1], deviceBin)
99104

100105
// Forward SIGQUIT from the go command to show backtraces from
101106
// the binary instead of from this wrapper.

0 commit comments

Comments
 (0)