From 2c1308daf3cc8975c9f5466de545a49bc634506d Mon Sep 17 00:00:00 2001 From: Dan Bond Date: Fri, 30 Jun 2017 15:44:21 +0100 Subject: [PATCH] Fix concurrency bug (#10) --- vape.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/vape.go b/vape.go index 0b54df9..7ad5b18 100644 --- a/vape.go +++ b/vape.go @@ -42,16 +42,18 @@ func NewVape(client HTTPClient, baseURL *url.URL, resCh chan CheckResult, errCh // Process takes a list of URIs and concurrently performs a smoke test on each. func (v Vape) Process(statusCodeChecks StatusCodeChecks) { // TODO: limit the numer of concurrent requests so we don't DoS the server - for _, check := range statusCodeChecks { - go func(check StatusCodeCheck) { - result, err := v.performCheck(check) - if err != nil { - v.errCh <- err - return - } - v.resCh <- result - }(check) - } + go func() { + for _, check := range statusCodeChecks { + go func(check StatusCodeCheck) { + result, err := v.performCheck(check) + if err != nil { + v.errCh <- err + return + } + v.resCh <- result + }(check) + } + }() } // performCheck checks the status code of a HTTP request of a given URI.