-
Notifications
You must be signed in to change notification settings - Fork 537
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
base: main
Are you sure you want to change the base?
Conversation
@@ -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) |
There was a problem hiding this comment.
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
.
b121937
to
7d7b883
Compare
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
7d7b883
to
e33c20a
Compare
if err != nil { | ||
return nil, errors.Wrap(err, "create gzip reader") | ||
} | ||
|
||
defer func() { | ||
_ = gzReader.Close() |
There was a problem hiding this comment.
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.
Are you reading that from here? |
I'm reading it from here (stdlib vs klauspost).
To me it seems clear that it's referring to the returned 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. |
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
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]
.about-versioning.md
updated with experimental features.