caddyconfig: Fix httploader leak from unused responses (#5159)

fixes #5158

Signed-off-by: Chris Lahaye <mail@chrislahaye.com>

Signed-off-by: Chris Lahaye <mail@chrislahaye.com>
This commit is contained in:
Chris Lahaye 2022-10-24 19:58:30 +02:00 committed by GitHub
parent ed503118dd
commit bbe3663167
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -134,16 +134,16 @@ func doHttpCallWithRetries(ctx caddy.Context, client *http.Client, request *http
var err error
const maxAttempts = 10
// attempt up to 10 times
for i := 0; i < maxAttempts; i++ {
resp, err = attemptHttpCall(client, request)
if err != nil && i < maxAttempts-1 {
// wait 500ms before reattempting, or until context is done
select {
case <-time.After(time.Millisecond * 500):
case <-ctx.Done():
return resp, ctx.Err()
}
} else {
break
}
}