[Bug]: Race condition and misleading exception on concurrent preview generation requests for the same file #41225
Labels
0. Needs triage
Pending check for reproducibility or if it fits our roadmap
27-feedback
bug
feature: previews and thumbnails
Bug description
For context:
This issue was discoverd with nextcloud/deck#5035 which introduced a new feature that shows attachments of a card not only in the attachment list in the sidebar, but also as cover image to a card.
Uploading an image therefore triggers two concurrent preview generation request with different sizes, leading to a race condition in the Preview Generator.
The effect is that only one of the requests returns the preview image the other throws the missleading Exception:
Opening this issue is a followup to nextcloud/deck#5035 referenced in nextcloud/deck#5214.
I already did some debugging and the main issue occurs at the preview folder creation:
Where does the race condition occur?
It starts at
server/lib/private/Preview/Generator.php
Lines 594 to 605 in 43270c6
As both requests detect that the folder isn't there yet, both will attempt to create the new folder.
To my unterstanding from there it could go different routes dependent on the storage, for Deck it's the local storage.
Here's my debugging message and trace I got for the request that was slower on the local storage and therefore fails to create the new folder:
(Please disregard line numbers, I inserted debugging output that might have shifted things)
What fails is mkdir on the local storage which could be fixed (the quick and dirty solution) by not failing the mkdir if the folder is already exisit:
server/lib/private/Files/Storage/Local.php
Line 114 in 43270c6
Maybe a better solution would be to extend the error handling along the way at
server/lib/private/Files/Node/Folder.php
Lines 156 to 163 in efe68d0
This brings me to the misleading
NotPermittedException
Why misleading exception?
That the mkdir failed does not necessarily mean that this was because of permissions as my debug output shows.
Maybe a
GenericFileException
would be more accurate instead? Something like:I'm a little unsure about this, but shouldn't "checkPermissions(\OCP\Constants::PERMISSION_CREATE)" have already checked whether we have sufficient permissions to create a subfolder?
And why is NonExistingFolder not checking that it is really non existing in its constructor?
Steps to reproduce
Expected behavior
previews are generated regardless of concurrency
Installation method
Community Docker image
Nextcloud Server version
27
Operating system
Debian/Ubuntu
PHP engine version
PHP 8.1
Web server
Apache (supported)
Database engine version
SQlite
Is this bug present after an update or on a fresh install?
Fresh Nextcloud Server install
Are you using the Nextcloud Server Encryption module?
Encryption is Disabled
What user-backends are you using?
Configuration report
No response
List of activated Apps
No response
Nextcloud Signing status
No response
Nextcloud Logs
No response
Additional info
No response
The text was updated successfully, but these errors were encountered: