From c291acd96e9a7dffc5bbf19973fa09be590d3b06 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Mon, 12 Jan 2015 17:43:00 -0800 Subject: [PATCH] api: Minor cleanups in lock --- api/lock.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/lock.go b/api/lock.go index 0d95d1c839..5885702465 100644 --- a/api/lock.go +++ b/api/lock.go @@ -70,6 +70,9 @@ func (c *Client) LockKey(key string) (*Lock, error) { // to acquire and release the mutex. The key used must have // write permissions. func (c *Client) LockOpts(opts *LockOptions) (*Lock, error) { + if opts.Key == "" { + return nil, fmt.Errorf("missing key") + } if opts.SessionName == "" { opts.SessionName = DefaultLockSessionName } @@ -264,17 +267,16 @@ func (l *Lock) renewSession(id string, doneCh chan struct{}) { // monitorLock is a long running routine to monitor a lock ownership // It closes the stopCh if we lose our leadership. func (l *Lock) monitorLock(session string, stopCh chan struct{}) { + defer close(stopCh) kv := l.c.KV() opts := &QueryOptions{RequireConsistent: true} WAIT: pair, meta, err := kv.Get(l.opts.Key, opts) if err != nil { - close(stopCh) return } if pair != nil && pair.Session == session { opts.WaitIndex = meta.LastIndex goto WAIT } - close(stopCh) }