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

x-pack/filebeat/input/httpjson: Close connections properly #39790

Merged
merged 7 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ The list below covers the major changes between 7.0.0-rc2 and main only.
- Skip flakey metrics test on windows in filebeat httpjson input. {issue}39676[39676] {pull}39678[39678]
- Fix flakey test on Windows 2022 in packetbeat/route. {issue}39698[39698] {pull}39822[39822]
- Fix bug in minimum length for request trace logging. {pull}39834[39834]
- Close connections properly in Filbeat's HTTPJSON input. {pull}39790[39790]

==== Added

Expand Down
6 changes: 6 additions & 0 deletions x-pack/filebeat/input/httpjson/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ func (p *Policy) CustomRetryPolicy(ctx context.Context, resp *http.Response, err
// errors and may relate to outages on the server side. This will catch
// invalid response codes as well, like 0 and 999.
if resp.StatusCode == 0 || (resp.StatusCode >= 500 && resp.StatusCode != 501) {
defer func() {
if resp.Body != nil {
shmsr marked this conversation as resolved.
Show resolved Hide resolved
_, _ = io.Copy(io.Discard, resp.Body)
resp.Body.Close()
}
}()
return true, nil
}

Expand Down
7 changes: 1 addition & 6 deletions x-pack/filebeat/input/httpjson/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ func (r *requester) processChainPaginationEvents(ctx context.Context, trCtx *tra
if err != nil {
return -1, fmt.Errorf("failed to collect response: %w", err)
}

// store data according to response type
if i == len(r.requestFactories)-1 && len(ids) != 0 {
finalResps = append(finalResps, httpResp)
Expand All @@ -702,12 +703,6 @@ func (r *requester) processChainPaginationEvents(ctx context.Context, trCtx *tra
n += p.eventCount()
}

defer func() {
if httpResp != nil && httpResp.Body != nil {
httpResp.Body.Close()
}
}()

return n, nil
}

Expand Down
Loading