Skip to content

Commit

Permalink
fix(http): closed http resp that occupies underlying connection (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
powerfooI authored Mar 27, 2024
1 parent 8da7488 commit 4a12e55
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions internal/telemetry/throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,18 @@ func (t *throttler) startWorkers() {
return
}
res, err := t.sendTelemetryRecord(record)
if debugMode {
if err != nil {
getLogger().Printf("send telemetry record error: %v\n", err)
if err == nil && res != nil && res.Body != nil {
if debugMode {
bts, err := io.ReadAll(res.Body)
if err != nil {
getLogger().Printf("read response body error: %v\n", err)
} else {
getLogger().Printf("[Event %s.%s] %s\n", record.ResourceType, record.EventType, string(bts))
}
} else {
_, _ = io.Copy(io.Discard, res.Body)
}
bts, err := io.ReadAll(res.Body)
if err != nil {
getLogger().Printf("read response body error: %v\n", err)
}
getLogger().Printf("[Event %s.%s] %s\n", record.ResourceType, record.EventType, string(bts))
_ = res.Body.Close()
}
case <-ctx.Done():
getLogger().Println(ctx.Err())
Expand Down

0 comments on commit 4a12e55

Please sign in to comment.