Race condition in downsize_upload script

Problem

When using the downsize_upload.rb script to shrink uploaded images, some images was changed while the posts that use these images remain unchanged. This could lead to some posts’ images appear like they have disappeared.

Possible Cause

In shrink_uploaded_image.rb , after selecting posts to transform(update image url), there may still be a new post that use the uploaded image. But the new post did not got transformed and use a old reference to a image, like the one in the image above.

Posts that need to be transformed are first selected here:

https://github.com/discourse/discourse/blob/d0ef952af296f4fe00c8be56f4e8cede8095d2d6/lib/shrink_uploaded_image.rb#L73

After this point, any new posts that use the image being transformed will not got their link updated, leading to a broken image.

2 Likes