Skip to content
Snippets Groups Projects

Fix LFS timeouts when trying to save large files

Merged Stan Hu requested to merge sh-fix-lfs-from-moving-across-filesystems into master
3 files
+ 46
0
Compare changes
  • Side-by-side
  • Inline
Files
3
  • 0e9d3e37
    The following was happening:
    
    1. Workhorse stores an LFS file in /var/opt/gitlab/gitlab-rails/shared/lfs-objects
    2. CarrierWave then renames the file to a temporary directory (e.g. /opt/gitlab/embedded/service/gitlab-rails/tmp)
    3. CarrierWave then renames the file to its final location (e.g. /var/opt/gitlab/gitlab-rails/shared/lfs-objects)
    
    When the LFS upload path was on a different filesystem than the Rails
    installation, step 2 could take a longer than 10 seconds, at which point Workhorse
    would time out with "badgateway: failed after 10s: context canceled".
    
    This change makes the work path in the same root as the LFS cache path, preventing moves
    across filesystems.
    
    Closes #33218
@@ -12,4 +12,20 @@ def cache_dir
def filename
model.oid[4..-1]
end
private
# To prevent LFS files from moving across filesystems, override the default
# implementation:
# http://github.com/carrierwaveuploader/carrierwave/blob/v1.0.0/lib/carrierwave/uploader/cache.rb#L181-L183
def workfile_path(for_file = original_filename)
# To be safe, we keep this directory outside of the the cache directory
# because calling CarrierWave.clean_cache_files! will remove any files in
# the cache directory.
File.join(work_dir, @cache_id, version_name.to_s, for_file)
end
def work_dir
File.join(Gitlab.config.lfs.storage_path, 'tmp', 'work')
end
end
Loading