From 146adcf7fd7a7275d1e9b4c7e60ed4901c05c570 Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Fri, 31 Aug 2018 06:38:38 -0400 Subject: [PATCH] fix panic when there were no recent errors --- reflector/stats.go | 10 ++++++---- updater/updater.go | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/reflector/stats.go b/reflector/stats.go index 5501bbe..c0f9b57 100644 --- a/reflector/stats.go +++ b/reflector/stats.go @@ -102,8 +102,10 @@ func (s *stats) log() { delete(s.errors, name) } s.mu.Unlock() - s.logger.Printf( - "Stats: %d blobs, %d streams, errors: %s", - blobs, streams, errStr[:len(errStr)-2], // trim last comma and space - ) + + if len(errStr) > 2 { + errStr = errStr[:len(errStr)-2] // trim last comma and space + } + + s.logger.Printf("Stats: %d blobs, %d streams, errors: %s", blobs, streams, errStr) } diff --git a/updater/updater.go b/updater/updater.go index dc8cd96..dc875e1 100644 --- a/updater/updater.go +++ b/updater/updater.go @@ -15,8 +15,9 @@ import ( // TODO: this needs to be shut down cleanly func Run(url, updateCmd string) { + t := time.NewTicker(1 * time.Minute) for { - <-time.After(1 * time.Minute) + <-t.C r, err := http.Head(url) if err != nil {