Skip to content

Commit

Permalink
Bug fix for duplicate log events by resetting the response body strea…
Browse files Browse the repository at this point in the history
…m in agent health (#1337)
  • Loading branch information
bryce-carey authored Sep 5, 2024
1 parent 9a3f11f commit 76279c7
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion extension/agenthealth/handler/stats/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ func rejectedEntityInfoExists(r *http.Response) bool {
if r == nil || r.Body == nil {
return false
}
defer r.Body.Close()
bodyBytes, err := io.ReadAll(r.Body)
r.Body.Close()
// Reset the response body stream since it can only be read once. Not doing this results in duplicate requests.
// See https://stackoverflow.com/questions/33532374/in-go-how-can-i-reuse-a-readcloser
r.Body = io.NopCloser(bytes.NewReader(bodyBytes))
if err != nil {
return false
}
Expand Down

0 comments on commit 76279c7

Please sign in to comment.