advanced-nova-media-library
advanced-nova-media-library copied to clipboard
[BUG] Race-condition when uploading multiple media with conversions => No Query Results
There seems to be an issue when uploading multiple (big) files with conversions.
All the jobs, except the last will fail with the No Query Results
error. If one however adds ->delay(10)
at the following line: https://github.com/spatie/laravel-medialibrary/blob/21c40b4d06bd8d16c0454f553c6de4d1e35aba3e/src/Conversions/FileManipulator.php#L94
Or extends the job as follows:
class CustomPerformConversionsJob extends PerformConversionsJob
{
/**
* The number of seconds before the job should be made available.
*
* @var \DateTimeInterface|\DateInterval|int|null
*/
public $delay = 10;
}
The issue will be gone - I don't know if this issue only happens when using the Redis Driver (and Horizon) but it was a hard one to track down and find a fix for.
Like I said, I think there's a race-condition somewhere, probably firing the job off without saving the media first. It could also be that the database is slower than the queue workers resulting in a non-fixable race-condition.
What I tried: I tried delays of 1, 2 and 4 seconds but 10 seconds seems to do the most reliable job
EDIT: Above fix doesn't work if you try with more files... seems to depend on the amount of files...
NOTE: Tried to get the issue resolved at https://github.com/spatie/laravel-medialibrary/issues/2213 - no luck
If anyone else like me stumbles across this. The issue is jobs firing before the DB transaction has completed. To fix this follow - https://github.com/spatie/laravel-medialibrary/issues/1304#issuecomment-858041770