From 85752ab36df2e6a87463fe85861d692c0b7b6389 Mon Sep 17 00:00:00 2001 From: itsdalmo Date: Mon, 25 Feb 2019 10:24:04 +0100 Subject: [PATCH] Defer call to stop ticker when spot listener returns --- spot.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/spot.go b/spot.go index 3c98b3f..fd1be56 100644 --- a/spot.go +++ b/spot.go @@ -39,14 +39,15 @@ func (l *SpotListener) Start(ctx context.Context, notices chan<- TerminationNoti if !l.metadata.Available() { return errors.New("ec2 metadata is not available") } - - tockChan := time.NewTicker(l.interval).C - + + ticker := time.NewTicker(l.interval) + defer ticker.Stop() + for { select { case <-ctx.Done(): return nil - case <-tockChan: + case <-ticker.C: log.Debug("Polling ec2 metadata for spot termination notices") out, err := l.metadata.GetMetadata("spot/termination-time")