Skip to content
Snippets Groups Projects
Unverified Commit d402216e authored by Travis Ralston's avatar Travis Ralston Committed by GitHub
Browse files

Ensure thumbnail readers are cleaned up/read upon error (#585)

* Ensure thumbnail readers are cleaned up/read upon error

* Changelog
parent 1fe0d069
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
* Purging old media has been fixed to actually identify old media.
* JPEG thumbnails will now use sensible extensions.
* Fixed directory permissions when exporting MMR to Synapse.
* In some rare cases, memory usage may have leaked due to thumbnail error handling. This has been fixed.
## [1.3.4] - February 9, 2024
......
......@@ -119,6 +119,12 @@ func main() {
thumb, err := thumbnailing.GenerateThumbnail(src, record.ContentType, s.width, s.height, s.method, false, ctx)
if err != nil {
if thumb.Reader != nil {
err2 := thumb.Reader.Close()
if err2 != nil {
ctx.Log.Warn("Non-fatal error cleaning up thumbnail stream: ", err2)
}
}
ctx.Log.Debug("Error generating thumbnail (you can probably ignore this). ", s, err)
return
}
......
......@@ -46,6 +46,12 @@ func Generate(ctx rcontext.RequestContext, mediaRecord *database.DbMedia, width
i, err := thumbnailing.GenerateThumbnail(mediaStream, fixedContentType, width, height, method, animated, ctx)
if err != nil {
if i.Reader != nil {
err2 := i.Reader.Close()
if err2 != nil {
ctx.Log.Warn("Non-fatal error cleaning up thumbnail stream: ", err2)
}
}
if errors.Is(err, common.ErrMediaDimensionsTooSmall) {
metric.Inc()
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment