martabitbrain / directus-extension-sane-image-size

Simple Directus Extension Hook that resizes an image to a maximum size on upload.
MIT License
11 stars 1 forks source link

Directus crashes while trying to access an avif derivative of the file just uploaded #5

Open martabitbrain opened 5 months ago

martabitbrain commented 5 months ago

When this extension is enabled (and the sleep time is lower than 2000 seconds, but depends on the image), just after the transformation is generated and the file is going to be saved, something (might be Directus app) tries to download a non existent image derivative from the image we just saved and it crashes.

[11:39:05] POST /files 200 67ms
[11:39:05] GET /files/78edb438-c02c-494d-932b-0addf8cd7a6f?fields[]=id&fields[]=title&fields[]=width&fields[]=height&fields[]=filesize&fields[]=type&fields[]=filename_download&fields[]=modified_on 200 9ms
[11:39:05] GET /files/78edb438-c02c-494d-932b-0addf8cd7a6f?fields[]=id&fields[]=type&fields[]=title&fields[]=title 200 19ms
node:events:496
      throw er; // Unhandled 'error' event
      ^

Error: ENOENT: no such file or directory, open '/home/myddna/projects/directus/web-backend/uploads/78edb438-c02c-494d-932b-0addf8cd7a6f__7809681e43a17c0d8ad77890c0e89a2f36978e77.avif'

I have no Idea how this could be solved right now :(

martabitbrain commented 3 months ago

When we perform the files.uploadOne operation on a file replacement, directus deletes the old system thumbnails. This sometimes creates a race condition that crashes directus when the frontend requests the thumbnail. Why it does crash instead of generating it again I have no idea.