From b8f4f6d3e2642008df03ba4dbf7738920d973011 Mon Sep 17 00:00:00 2001 From: Bruno Miguel Custodio Date: Fri, 8 Sep 2017 15:21:06 +0100 Subject: [PATCH] Delete lock info when unlocking. --- backend/remote-state/etcdv3/client.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/backend/remote-state/etcdv3/client.go b/backend/remote-state/etcdv3/client.go index 7d3f1500d..4cb1363dd 100644 --- a/backend/remote-state/etcdv3/client.go +++ b/backend/remote-state/etcdv3/client.go @@ -116,6 +116,17 @@ func (c *RemoteClient) Unlock(id string) error { return c.unlock(id) } +func (c *RemoteClient) deleteLockInfo(info *state.LockInfo) error { + res, err := c.Client.KV.Delete(context.TODO(), c.Key+lockInfoSuffix) + if err != nil { + return err + } + if res.Deleted == 0 { + return fmt.Errorf("No keys deleted for %s when deleting lock info.", c.Key+lockInfoSuffix) + } + return nil +} + func (c *RemoteClient) getLockInfo() (*state.LockInfo, error) { res, err := c.Client.KV.Get(context.TODO(), c.Key+lockInfoSuffix) if err != nil { @@ -181,6 +192,9 @@ func (c *RemoteClient) unlock(id string) error { var errs error + if err := c.deleteLockInfo(c.info); err != nil { + errs = multierror.Append(errs, err) + } if err := c.etcdMutex.Unlock(context.TODO()); err != nil { errs = multierror.Append(errs, err) }