From 9043966efdab6e8e12c73772de070e25c4a50bc1 Mon Sep 17 00:00:00 2001 From: Hamish Date: Fri, 6 Jul 2018 10:55:25 +0100 Subject: [PATCH] Fix lock and semaphore timeouts --- api/lock.go | 5 +++-- api/semaphore.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/api/lock.go b/api/lock.go index 41f72e7d23..82339cb744 100644 --- a/api/lock.go +++ b/api/lock.go @@ -181,11 +181,12 @@ WAIT: // Handle the one-shot mode. if l.opts.LockTryOnce && attempts > 0 { elapsed := time.Since(start) - if elapsed > qOpts.WaitTime { + if elapsed > l.opts.LockWaitTime { return nil, nil } - qOpts.WaitTime -= elapsed + // Query wait time should not exceed the lock wait time + qOpts.WaitTime = l.opts.LockWaitTime - elapsed } attempts++ diff --git a/api/semaphore.go b/api/semaphore.go index d0c5741778..bc4f885fec 100644 --- a/api/semaphore.go +++ b/api/semaphore.go @@ -199,11 +199,12 @@ WAIT: // Handle the one-shot mode. if s.opts.SemaphoreTryOnce && attempts > 0 { elapsed := time.Since(start) - if elapsed > qOpts.WaitTime { + if elapsed > s.opts.SemaphoreWaitTime { return nil, nil } - qOpts.WaitTime -= elapsed + // Query wait time should not exceed the semaphore wait time + qOpts.WaitTime = s.opts.SemaphoreWaitTime - elapsed } attempts++