Skip to content

Commit

Permalink
Ensure heartbeats run until agent is stopped
Browse files Browse the repository at this point in the history
Fixes a regression in #971
  • Loading branch information
lox committed Apr 19, 2019
1 parent 3764cec commit 652fa78
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion agent/agent_worker.go
@@ -1,6 +1,7 @@
package agent

import (
"context"
"fmt"
"strings"
"sync"
Expand Down Expand Up @@ -136,6 +137,10 @@ func (a *AgentWorker) Start() error {
// Create the ticker
a.ticker = time.NewTicker(pingInterval)

// Use a context to run heartbeats for as long as the agent runs for
heartbeatCtx, cancel := context.WithCancel(context.Background())
defer cancel()

// Setup and start the heartbeater
go func() {
for {
Expand All @@ -150,7 +155,7 @@ func (a *AgentWorker) Start() error {
err, heartbeatInterval, time.Now().Sub(lastHeartbeat))
}

case <-a.stop:
case <-heartbeatCtx.Done():
a.logger.Debug("Stopping heartbeats")
return
}
Expand Down

0 comments on commit 652fa78

Please sign in to comment.