Merge pull request #2495 from hashicorp/b-vault-stop-renew

Stop Vault token renew on task exit
This commit is contained in:
Alex Dadgar
2017-03-28 11:14:18 -07:00
committed by GitHub
2 changed files with 5 additions and 7 deletions

View File

@@ -553,6 +553,10 @@ func (f *tokenFuture) Get() string {
// allows setting the initial Vault token. This is useful when the Vault token
// is recovered off disk.
func (r *TaskRunner) vaultManager(token string) {
// Always stop renewing the token. If token is empty or untracked, it is a
// no-op so this is always safe.
defer r.vaultClient.StopRenewToken(r.vaultFuture.Get())
// updatedToken lets us store state between loops. If true, a new token
// has been retrieved and we need to apply the Vault change mode
var updatedToken bool

View File

@@ -457,9 +457,8 @@ func (c *vaultClient) renew(req *vaultClientRenewalRequest) error {
// item is tracked by the renewal loop, stop renewing
// it by removing the corresponding heap entry.
if err := c.heap.Remove(req.id); err != nil {
return fmt.Errorf("failed to remove heap entry. err: %v", err)
return fmt.Errorf("failed to remove heap entry: %v", err)
}
delete(c.heap.heapMap, req.id)
// Report the fatal error to the client
req.errCh <- renewalErr
@@ -578,15 +577,10 @@ func (c *vaultClient) stopRenew(id string) error {
return nil
}
// Remove the identifier from the heap
if err := c.heap.Remove(id); err != nil {
return fmt.Errorf("failed to remove heap entry: %v", err)
}
// Delete the identifier from the map only after the it is removed from
// the heap. Heap's remove method relies on the heap map.
delete(c.heap.heapMap, id)
// Signal an update to the renewal loop.
if c.running {
select {