Skip to content

Commit

Permalink
Merge pull request #14 from hellofresh/hotfix/send-on-closed-channel-…
Browse files Browse the repository at this point in the history
…during-timeout

Fix send on closed channel during timeout
  • Loading branch information
rafaeljesus authored Mar 29, 2018
2 parents 8b73daf + 3389ad7 commit f29ba41
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions health.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,24 @@ func HandlerFunc(w http.ResponseWriter, r *http.Request) {
defer mu.Unlock()

status := statusOK
total := len(checks)
failures := make(map[string]string)
resChan := make(chan checkResponse, len(checks))
defer close(resChan)
resChan := make(chan checkResponse, total)

var wg sync.WaitGroup
wg.Add(total)

go func() {
defer close(resChan)
wg.Wait()
}()

for _, c := range checks {
go func(c Config) {
resChan <- checkResponse{
name: c.Name,
skipOnErr: c.SkipOnErr,
err: c.Check(),
defer wg.Done()
select {
case resChan <- checkResponse{c.Name, c.SkipOnErr, c.Check()}:
default:
}
}(c)

Expand Down

0 comments on commit f29ba41

Please sign in to comment.