From 1664ff96f76e4f2cfdbaabfe286cdeff0426a013 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Fri, 25 Mar 2016 15:40:44 +0100 Subject: [PATCH] misc/ios: fix exec wrapper locking The exec wrapper lock file was opened, locked and then never used again, assuming it would close and unlock at process exit. However, the garbage collector could collect and run the *os.File finalizer that closes the file prematurely, rendering the lock ineffective. Make the lock global so that the lock is live during the entire execution. (Hopefully) fix the iOS builders. Change-Id: I62429e92042a0a49c4f1ea553fdb32b6ea53a43e Reviewed-on: https://go-review.googlesource.com/21137 Reviewed-by: David Crawshaw --- misc/ios/go_darwin_arm_exec.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/misc/ios/go_darwin_arm_exec.go b/misc/ios/go_darwin_arm_exec.go index 6f0b98f112..1eeb289c7d 100644 --- a/misc/ios/go_darwin_arm_exec.go +++ b/misc/ios/go_darwin_arm_exec.go @@ -50,6 +50,11 @@ var ( teamID string ) +// lock is a file lock to serialize iOS runs. It is global to avoid the +// garbage collector finalizing it, closing the file and releasing the +// lock prematurely. +var lock *os.File + func main() { log.SetFlags(0) log.SetPrefix("go_darwin_arm_exec: ") @@ -84,7 +89,7 @@ func main() { // The lock file is never deleted, to avoid concurrent locks on distinct // files with the same path. lockName := filepath.Join(os.TempDir(), "go_darwin_arm_exec.lock") - lock, err := os.OpenFile(lockName, os.O_CREATE|os.O_RDONLY, 0666) + lock, err = os.OpenFile(lockName, os.O_CREATE|os.O_RDONLY, 0666) if err != nil { log.Fatal(err) } -- 2.48.1