Skip to content

`BackgroundMoveWorker` is triggered twice when LFS object is uploaded (i.e. `file_change?` bug)

Summary

We have the following code to detect if the file(i.e. mounted_as) was changed so that BackgroundMoveWorker can migrate the object from FS to OS.

https://gitlab.com/gitlab-org/gitlab-ee/blob/master/ee/app/uploaders/object_storage.rb#L88-93

def changed_mounts
  self.class.uploaders.select do |mount, uploader_class|
    mounted_as = uploader_class.serialization_column(self.class, mount)
    mount if send(:"#{mounted_as}_changed?") # rubocop:disable GitlabSecurity/PublicSend
  end.keys
end

But this is triggered even if it's LfsObject.create(oid: oid, size: size). This is because Carrierwave initiates file and it's considered as changed from nil to <XXXUploader ....

Steps to reproduce

LFS push

Possible fixes

def changed_mounts
  self.class.uploaders.select do |mount, uploader_class|
    mounted_as = uploader_class.serialization_column(self.class, mount)
    mount if send(:"#{mounted_as}_changed?") && send(:"#{mounted_as}")&.exists? # rubocop:disable GitlabSecurity/PublicSend
  end.keys
end