Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 5bc0f11

Browse files
committed
Handle response errors more properly
Value returned by http client Do function is nil or already closed if there is any error. See https://golang.org/src/net/http/client.go?s=16518:16570#L480 Therefore in order to avoid memory leaks in a potential ioutil.ReadAll error and to be Go idioms compliant, the response body is deferred to be closed immediately after checking there is no error with the Do function. CAT: #fix REF: #8 THX: @Zambiorix
1 parent 79e54fc commit 5bc0f11

File tree

1 file changed

+1
-1
lines changed
  • service/lambda/runtime/net/apigatewayproxy

1 file changed

+1
-1
lines changed

service/lambda/runtime/net/apigatewayproxy/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ func (s *Server) Handle(evt json.RawMessage, ctx *runtime.Context) (gwres *Respo
144144
log.Println(err)
145145
return
146146
}
147+
defer res.Body.Close()
147148

148149
body, err := ioutil.ReadAll(res.Body)
149150
if err != nil {
150151
log.Println(err)
151152
return
152153
}
153-
res.Body.Close()
154154

155155
ct := res.Header.Get("Content-Type")
156156
if ct == "" {

0 commit comments

Comments
 (0)