Skip to content

Commit

Permalink
Merge pull request #150 from hxzqlh/master
Browse files Browse the repository at this point in the history
fix http response memory leak
  • Loading branch information
zouyx committed Nov 26, 2020
2 parents bf8c0b4 + 3feed28 commit ae9aad8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions protocol/http/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ func Request(requestURL string, connectionConfig *env.ConnectConfig, callBack *C
}
client.Transport = tp
retry := 0
var responseBody []byte
var res *http.Response
var retries = maxRetries
if connectionConfig != nil && !connectionConfig.IsRetry {
retries = 1
Expand Down Expand Up @@ -119,7 +117,10 @@ func Request(requestURL string, connectionConfig *env.ConnectConfig, callBack *C
}
}

res, err = client.Do(req)
res, err := client.Do(req)
if res != nil {
defer res.Body.Close()
}

if res == nil || err != nil {
log.Error("Connect Apollo Server Fail,url:%s,Error:%s", requestURL, err)
Expand All @@ -131,7 +132,7 @@ func Request(requestURL string, connectionConfig *env.ConnectConfig, callBack *C
//not modified break
switch res.StatusCode {
case http.StatusOK:
responseBody, err = ioutil.ReadAll(res.Body)
responseBody, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Error("Connect Apollo Server Fail,url:%s,Error:", requestURL, err)
// if error then sleep
Expand Down

0 comments on commit ae9aad8

Please sign in to comment.