Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parallel downloads of the same image #2723

Merged
merged 1 commit into from
Oct 11, 2024

Commits on Oct 11, 2024

  1. Fix parallel downloads of the same image

    When starting multiple vms in parallel using the same uncached yet
    image, we downloaded the data to the same temporary file (data.tmp) and
    wrote metadata to the same files (url, time, type, {digest}.digest). We
    could fail in many ways:
    
    - One process removes the cache directory when another tries to rename a
      temporary file to the destination file.
    - One process fails to remove the cache directory since another process
      started to download and the directory is not empty.
    - Corrupting data when writing to the same file from multiple processes.
      Mostly likely when writing downloaded data.
    
    Fixes:
    
    - Do not remove the cache directory before the download. This avoids the
      failing to remove non-empty directory, and failure to rename a
      temporary file.
    - Write all data to temporary files, replacing the destination file when
      the write is complete. This avoid corrupted data.
    - Do not remove destination file when creating a new temporary file or
      renaming since creating a file truncate existing file and renaming
      replace it.
    
    Issues:
    
    - On windows os.Rename is not atomic, but it should work when using
      NTFS.
    - On failures we may have lefover temporary files ({name}.tmp.{pid}).
    
    Fixes lima-vm#2722
    
    Signed-off-by: Nir Soffer <[email protected]>
    nirs committed Oct 11, 2024
    Configuration menu
    Copy the full SHA
    f2fb061 View commit details
    Browse the repository at this point in the history