Concurrency: Target uploaded file already exists, aborting operation

twm

Network license
License owner
Same bug in new version (3.14.1)



 

Rodolfo

Chevereto Developer
Chevereto Staff
This is the relevant code:

app/lib/classes/class.upload.php:
        /*
         * Set uploaded_file
         * Local storage uploads will be allocated at the target destination
         * External storage will be allocated to the temp directory
         */
        if ($this->storage_id) {
            $this->uploaded_file = G\forward_slash(dirname($this->downstream)) . '/' . Storage::getStorageValidFilename($this->fixed_filename, $this->storage_id, $this->options['filenaming'], $this->destination);
        } else {
            $this->uploaded_file = G\name_unique_file($this->destination, $this->options['filenaming'], $this->fixed_filename);
        }

        $this->source = [
            'filename' => $this->source_filename, // file.ext
            'name' => $this->source_name, // file
            'image_exif' => $this->source_image_exif, // exif-data array
            'fileinfo' => G\get_image_fileinfo($this->downstream), // fileinfo array
        ];

        // 666 because concurrency is evil
        if (stream_resolve_include_path($this->downstream) == false) {
            throw new UploadException('Concurrency: Downstream gone, aborting operation', 666);
        }
        if (stream_resolve_include_path($this->uploaded_file) != false) {
            throw new UploadException('Concurrency: Target uploaded file already exists, aborting operation', 666);
        }
The only way to trigger concurrency is if an operation (op#2) happens to sneak between lines 12-23 (while doing op#1). This could be happening because there's too much concurrent uploading in your website. You should decrease the number of simultaneous uploads as your machine can't keep the frequency of the upload requests being made.

Other factors could be also triggering this issue, like using IDs for filenames. If you use random or mixed it should significantly decrease the chances for concurrency issues.

dashboard/settings/image-upload

1585237719087.png
 
  • Like
Reactions: twm
Top