Make soong lock file sync time configurable..

- Add SOONG_LOCK_TIMEOUT environmental variable for users to set a
duration (e.g. 1h), which defaults to the current 10 seconds.
- Instead of logging once per second waiting to acquire the lock,
only log once before the first wait

Fixes: 131854539
Test: make; open another tab and make
Change-Id: I0a02a1b071964f74473a5f55034f916526e1b309
This commit is contained in:
Amin Shaikh 2019-05-23 18:29:18 -04:00
parent a725681ed8
commit de730781d9

View file

@ -34,6 +34,14 @@ func BecomeSingletonOrFail(ctx Context, config Config) (lock *fileLock) {
if err != nil { if err != nil {
ctx.Logger.Fatal(err) ctx.Logger.Fatal(err)
} }
lockfilePollDuration := time.Second
lockfileTimeout := time.Second * 10
if envTimeout := os.Getenv("SOONG_LOCK_TIMEOUT"); envTimeout != "" {
lockfileTimeout, err = time.ParseDuration(envTimeout)
if err != nil {
ctx.Logger.Fatalf("failure parsing SOONG_LOCK_TIMEOUT %q: %s", envTimeout, err)
}
}
err = lockSynchronous(*lockingInfo, newSleepWaiter(lockfilePollDuration, lockfileTimeout), ctx.Logger) err = lockSynchronous(*lockingInfo, newSleepWaiter(lockfilePollDuration, lockfileTimeout), ctx.Logger)
if err != nil { if err != nil {
ctx.Logger.Fatal(err) ctx.Logger.Fatal(err)
@ -41,9 +49,6 @@ func BecomeSingletonOrFail(ctx Context, config Config) (lock *fileLock) {
return lockingInfo return lockingInfo
} }
var lockfileTimeout = time.Second * 10
var lockfilePollDuration = time.Second
type lockable interface { type lockable interface {
tryLock() error tryLock() error
Unlock() error Unlock() error
@ -80,15 +85,18 @@ func lockSynchronous(lock lockable, waiter waiter, logger logger.Logger) (err er
return nil return nil
} }
waited = true
done, description := waiter.checkDeadline() done, description := waiter.checkDeadline()
if !waited {
logger.Printf("Waiting up to %s to lock %v to ensure no other Soong process is running in the same output directory\n", description, lock.description())
}
waited = true
if done { if done {
return fmt.Errorf("Tried to lock %s, but timed out %s . Make sure no other Soong process is using it", return fmt.Errorf("Tried to lock %s, but timed out %s . Make sure no other Soong process is using it",
lock.description(), waiter.summarize()) lock.description(), waiter.summarize())
} else { } else {
logger.Printf("Waiting up to %s to lock %v to ensure no other Soong process is running in the same output directory\n", description, lock.description())
waiter.wait() waiter.wait()
} }
} }