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

fix: response body after HTTP error should be closed #106

Merged
merged 8 commits into from
Sep 27, 2024
Merged

Conversation

karel-rehor
Copy link
Contributor

@karel-rehor karel-rehor commented Sep 26, 2024

Closes #102

Proposed Changes

  • when client.resolveHttpError returns an error, ensure that resp.Body.Close() gets called. Otherwise resources may be leaked.
  • log Warning of failure to close body, or Debug message on success.
  • adds tests of this new section of code

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • Tests pass
  • Commit messages are conventional
  • Sign CLA (if not already signed)

Copy link

codecov bot commented Sep 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.35%. Comparing base (68a0862) to head (5ab7992).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #106      +/-   ##
==========================================
+ Coverage   85.32%   85.35%   +0.03%     
==========================================
  Files          14       14              
  Lines        1124     1127       +3     
==========================================
+ Hits          959      962       +3     
  Misses        137      137              
  Partials       28       28              
Flag Coverage Δ
85.35% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

CHANGELOG.md Outdated
Comment on lines 3 to 10
### Features

1. [#105](https://github.com/InfluxCommunity/influxdb3-go/pull/105): Support newlines in tag values.

### Bug Fixes

1. [#106](https://github.com/InfluxCommunity/influxdb3-go/pull/106): Close `resp.Body` after HTTP error response is encountered.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both should be Bug Fixes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@karel-rehor karel-rehor requested a review from bednar September 26, 2024 14:22
Comment on lines 191 to 198
closingErr := resp.Body.Close()
if closingErr != nil {
slog.Warn(fmt.Sprintf("Failed to close response body on HTTP Error(%s): %s",
err.Error(),
closingErr.Error()))
} else {
slog.Debug(fmt.Sprintf("Closed response body on HTTP Error(%s)", err.Error()))
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move closing of the response body to the resolveHTTPError method and omit useless logging. As it is in the InfluxDB Go Client v2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved, and corresponding tests have been removed.

Copy link
Member

@bednar bednar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@karel-rehor karel-rehor merged commit 5671330 into main Sep 27, 2024
11 checks passed
@karel-rehor karel-rehor deleted the fix/issue102 branch September 27, 2024 09:00
@bednar bednar added this to the 0.11.0 milestone Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Response body is not closed on HTTP error
3 participants