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

Close gzip readers after use #9770

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Close gzip readers after use #9770

wants to merge 1 commit into from

Conversation

aknuds1
Copy link
Contributor

@aknuds1 aknuds1 commented Oct 29, 2024

What this PR does

I noticed that in most cases we don't close gzip readers after use, even though it's the caller's responsibility.

Which issue(s) this PR fixes or relates to

Checklist

  • Tests updated.
  • Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • about-versioning.md updated with experimental features.

@@ -78,10 +79,10 @@ func OTLPHandler(
return httpgrpc.Errorf(http.StatusUnsupportedMediaType, "unsupported compression: %s. Only \"gzip\" or no compression supported", contentEncoding)
}

var decoderFunc func(io.ReadCloser) (req pmetricotlp.ExportRequest, uncompressedBodySize int, err error)
var decoderFunc func(io.Reader) (req pmetricotlp.ExportRequest, uncompressedBodySize int, err error)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function shouldn't close the passed reader, so might as well use io.Reader.

@aknuds1 aknuds1 marked this pull request as ready for review October 29, 2024 17:29
@aknuds1 aknuds1 requested a review from a team as a code owner October 29, 2024 17:29
@aknuds1 aknuds1 added the chore label Oct 29, 2024
Signed-off-by: Arve Knudsen <[email protected]>
if err != nil {
return nil, errors.Wrap(err, "create gzip reader")
}

defer func() {
_ = gzReader.Close()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no logger available in this context, to log an eventual error.

@bboreham
Copy link
Contributor

it's the caller's responsibility

Are you reading that from here?
It seems ambiguous to me whether it means the Reader passed in or the Reader returned.
I tend towards the former, given that Close() on the gzip decompressor doesn't do anything.

@aknuds1
Copy link
Contributor Author

aknuds1 commented Oct 30, 2024

Are you reading that from here?

I'm reading it from here (stdlib vs klauspost).

It seems ambiguous to me whether it means the Reader passed in or the Reader returned.

To me it seems clear that it's referring to the returned gzip.Reader, especially since it links to that type.

AFAICT, the gzip compressor Close method doesn't do anything but return an eventual error (for invalid checksum?), but that's an implementation detail and could change (considering the documentation indicates the caller should close the reader). Also, I don't think it's a bad idea to consistently log any returned error (as we already do in one call site), if we do have a logger.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants