diff --git a/vault/auth.go b/vault/auth.go index 0c88561da..31f33260b 100644 --- a/vault/auth.go +++ b/vault/auth.go @@ -81,9 +81,13 @@ func (c *Core) enableCredentialInternal(ctx context.Context, entry *MountEntry, c.mountsLock.Lock() c.authLock.Lock() + locked := true unlock := func() { - c.authLock.Unlock() - c.mountsLock.Unlock() + if locked { + c.authLock.Unlock() + c.mountsLock.Unlock() + locked = false + } } defer unlock() @@ -224,7 +228,6 @@ func (c *Core) enableCredentialInternal(ctx context.Context, entry *MountEntry, c.logger.Error("failed to evaluate filtered paths", "error", err) unlock() - unlock = func() {} // We failed to evaluate filtered paths so we are undoing the mount operation if disableCredentialErr := c.disableCredentialInternal(ctx, entry.Path, MountTableUpdateStorage); disableCredentialErr != nil { c.logger.Error("failed to disable credential", "error", disableCredentialErr) diff --git a/vault/mount.go b/vault/mount.go index a4bc4c02e..a29b44b42 100644 --- a/vault/mount.go +++ b/vault/mount.go @@ -573,9 +573,13 @@ func (c *Core) mount(ctx context.Context, entry *MountEntry) error { func (c *Core) mountInternal(ctx context.Context, entry *MountEntry, updateStorage bool) error { c.mountsLock.Lock() c.authLock.Lock() + locked := true unlock := func() { - c.authLock.Unlock() - c.mountsLock.Unlock() + if locked { + c.authLock.Unlock() + c.mountsLock.Unlock() + locked = false + } } defer unlock() @@ -738,7 +742,6 @@ func (c *Core) mountInternal(ctx context.Context, entry *MountEntry, updateStora c.logger.Error("failed to evaluate filtered paths", "error", err) unlock() - unlock = func() {} // We failed to evaluate filtered paths so we are undoing the mount operation if unmountInternalErr := c.unmountInternal(ctx, entry.Path, MountTableUpdateStorage); unmountInternalErr != nil { c.logger.Error("failed to unmount", "error", unmountInternalErr)