Defect #44620
openPartially written thumbnails may be served
Description
Redmine::Thumbnail.generate writes the thumbnail directly to its final path and skips generation whenever a file already exists there. As a result, an incomplete thumbnail can be served in two cases.
First, a request that arrives while ImageMagick is still writing the thumbnail for another request receives an empty or truncated file. This can happen when several users open an issue with image attachments at the same time, and is more likely with PDF thumbnails, which take longer to generate. Since the ETag is based on the thumbnail path, browsers keep showing the broken image even after the thumbnail is complete.
Second, if ImageMagick fails or exceeds thumbnails_generation_timeout, the partially written file is left in place and served from then on. It can only be fixed by deleting the file manually.
The attached patch writes the thumbnail to a temporary file in the same directory, so that it can be atomically renamed to the target path once ImageMagick succeeds. Other requests therefore see either no file or the complete thumbnail. The temporary file is removed if ImageMagick fails or times out.
Files
No data to display