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

Merged
merged 1 commit into from
Jan 3, 2025
Merged

Close gzip readers after use #9770

merged 1 commit into from
Jan 3, 2025

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 force-pushed the arve/otlp-close-reader branch from b121937 to 7d7b883 Compare October 29, 2024 17:25
@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
@aknuds1 aknuds1 force-pushed the arve/otlp-close-reader branch from 7d7b883 to e33c20a Compare October 30, 2024 10:53
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.

@aknuds1 aknuds1 force-pushed the arve/otlp-close-reader branch from e33c20a to 35f63a4 Compare January 1, 2025 11:14
Signed-off-by: Arve Knudsen <[email protected]>
@aknuds1 aknuds1 force-pushed the arve/otlp-close-reader branch from 35f63a4 to f149f2d Compare January 2, 2025 18:23
@aknuds1 aknuds1 merged commit a51e622 into main Jan 3, 2025
29 checks passed
@aknuds1 aknuds1 deleted the arve/otlp-close-reader branch January 3, 2025 07:40
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.

3 participants