diff --git a/backend/remote-state/consul/client.go b/backend/remote-state/consul/client.go index a5578a3c13..8b4ed6e7ef 100644 --- a/backend/remote-state/consul/client.go +++ b/backend/remote-state/consul/client.go @@ -120,7 +120,7 @@ func (c *RemoteClient) Lock(info *state.LockInfo) (string, error) { lock, err := c.Client.LockOpts(opts) if err != nil { - return "", nil + return "", err } c.consulLock = lock @@ -143,14 +143,15 @@ func (c *RemoteClient) Lock(info *state.LockInfo) (string, error) { err = c.putLockInfo(info) if err != nil { - err = multierror.Append(err, c.Unlock("")) + err = multierror.Append(err, c.Unlock(info.ID)) return "", err } - return "", nil + return info.ID, nil } func (c *RemoteClient) Unlock(id string) error { + // this doesn't use the lock id, because the lock is tied to the consul client. if c.consulLock == nil || c.lockCh == nil { return nil } diff --git a/state/remote/testing.go b/state/remote/testing.go index bd71aefcbf..b379b509df 100644 --- a/state/remote/testing.go +++ b/state/remote/testing.go @@ -85,6 +85,10 @@ func TestRemoteLocks(t *testing.T, a, b Client) { t.Fatal("unable to obtain lock from client B") } + if lockIDB == lockIDA { + t.Fatalf("duplicate lock IDs: %q", lockIDB) + } + if err = lockerB.Unlock(lockIDB); err != nil { t.Fatal("error unlocking client B:", err) }