Skip to content

Commit

Permalink
fix nil pointer deference (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
1azunna authored Feb 7, 2022
1 parent cc0adf6 commit c490fec
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions internal/zapgo/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,27 @@ var retrySchedule = []time.Duration{
}

func (z *Zapgo) HealthCheck(url string) {
var response *http.Response
// Wait 10seconds before checking for liveness
time.Sleep(10 * time.Second)
for _, backoff := range retrySchedule {
resp, err := http.Get(url)
if err == nil {
if err != nil {
logrus.Warn("Container is not ready")
logrus.Warnf("Retrying in %v", backoff)
time.Sleep(backoff)
} else if err == nil {
response = resp
logrus.Info("Container initialized successfully!")
break
} else {
logrus.Fatal(err)
}
defer resp.Body.Close()

logrus.Warn("Container is not ready")
logrus.Warnf("Retrying in %v", backoff)
time.Sleep(backoff)
}
resp, _ := http.Get(url)
if resp == nil {
logrus.Error("Could not reach host")
if response == nil {
logrus.Error("Could not verify that zap is running.")
os.Exit(1)
}
defer resp.Body.Close()

}

0 comments on commit c490fec

Please sign in to comment.