Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to HTTP Connection Pooling #385

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/target/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,13 @@ func (ht *HTTPTarget) Write(messages []*models.Message) (*models.TargetWriteResu
errResult = multierror.Append(errResult, errors.New("Error sending request: "+err.Error()))
continue
}
defer resp.Body.Close()

// Ensure response body is always closed
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
// Drain and close the body for successful responses
_, _ = io.Copy(io.Discard, resp.Body)
resp.Body.Close()

for _, msg := range goodMsgs {
if msg.AckFunc != nil { // Ack successful messages
msg.AckFunc()
Expand All @@ -409,7 +413,10 @@ func (ht *HTTPTarget) Write(messages []*models.Message) (*models.TargetWriteResu
continue
}

// Process non-2xx responses
responseBody, err := io.ReadAll(resp.Body)
_, _ = io.Copy(io.Discard, resp.Body)
resp.Body.Close() // Explicitly close the body after reading

if err != nil {
failed = append(failed, goodMsgs...)
Expand Down