emencia / cmsplugin-blocks

A set of DjangoCMS plugins for structured contents in CMS pages
https://cmspluginblocks.readthedocs.io/
MIT License
2 stars 0 forks source link

Fix race condition bug with purge signal #29

Closed sveetch closed 2 months ago

sveetch commented 3 months ago

Describe the bug

We have a long ago knowed bug that may sometime purge files that are still used from an object.

This is something almost impossible to reproduce on local environment but erratically happen on deployed environments.

We searched a lot in smart-media and cmsplugin-blocks code to find something that could lead to this but there is nothing.

We hardly suspect it is related to a "race condition" with djangocms plugin way of saving and publishing, where it copies plugin from draft to published page object. During this job the image field may be empty and trigger a file purge. Also Django signal is known to not be totally threadsafe in some situations where CMS plugins fit.

To Reproduce

Sadly we don't have a clear scenario to reproduce it every time.

But commonly, this could happen when publishing a page with a plugin like Card which have an image. Then so the purge signal seems to remove the source image file, although we use a thumbnailer (which cache files are not managed with any purge signal) so it is not only visible at the time being (since the thumb is cached and still show well).

But once editing again the plugin then the thumbnailer try to build again the thumb but since the source has been removed and it is not able to do it and may lead to an error 500 or just empty broken image.

Expected behavior

The plugin images files managed with smart-media should not been purged if they are still used in objects, they should only be purged once user upload a new image file.

The fact is we probably won't be able to correctly manage this situation, we can't even reproduce it in local development and tests.

Solution 1

So, since this package is tied to DjangoCMS plugins and django-filer is hardly related to DjangoCMS, furthermore django-filer does not have any purge signal, have a file browser to see all files (so we could at least purge them manually) and have recent SVG support, the only proper solution is to move image file management to django-filer and drop smart-media.

Only problem i see there is how to implement the mass upload from Album plugin with django-filer.

Solution 2

Just disable purge signals on every models which define them and keep smart-media that would release a new version with a command line to manually purge medias which will be safe.

This is my preferred solution and i will investigate in priority.

Plateform

Versions

sveetch commented 2 months ago

Purge signal have been removed in v1.5.0