fix: close and drain the response body always (#8847)

This commit is contained in:
Harshavardhana
2020-01-21 02:46:58 -08:00
committed by GitHub
parent 3011692d93
commit e2b3c083aa
9 changed files with 17 additions and 4 deletions

View File

@@ -142,15 +142,14 @@ func (target *WebhookTarget) send(eventData event.Event) error {
resp, err := target.httpClient.Do(req)
if err != nil {
target.Close()
return err
}
defer resp.Body.Close()
io.Copy(ioutil.Discard, resp.Body)
if resp.StatusCode < 200 || resp.StatusCode > 299 {
// close any idle connections upon any error.
target.httpClient.CloseIdleConnections()
target.Close()
return fmt.Errorf("sending event failed with %v", resp.Status)
}