Skip to content

Commit f2636de

Browse files
authoredMay 25, 2022
Merge pull request #42 from planetlabs/close-response-body
Always close response body
2 parents 920883c + 9f4450a commit f2636de

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed
 

‎crawler/crawler.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/json"
77
"errors"
88
"fmt"
9+
"io"
910
"io/ioutil"
1011
"math"
1112
"math/rand"
@@ -93,8 +94,12 @@ func tryLoadUrl(loc *normurl.Locator, value any) error {
9394
if err != nil {
9495
return err
9596
}
96-
if resp.StatusCode != http.StatusOK {
97+
defer func() {
98+
_, _ = io.Copy(ioutil.Discard, resp.Body)
9799
_ = resp.Body.Close()
100+
}()
101+
102+
if resp.StatusCode != http.StatusOK {
98103
return fmt.Errorf("unexpected response for %s: %d", loc, resp.StatusCode)
99104
}
100105

0 commit comments

Comments
 (0)
Please sign in to comment.