fal-ai / fal

⚡ Fastest way to serve open source ML models to millions
https://fal.ai/docs
Apache License 2.0
509 stars 44 forks source link

fix(toolkit): fix race conditions in download_utils #258

Closed efiop closed 2 months ago

efiop commented 2 months ago

Make sure our files/directories are created in a temporary location that is on the same filesystem as the target to avoid unnecessary copies across filesystems and to make it possible to (semi)atomically move them into place using os.rename.

I don't have good examples yet, but this might make some of our apps faster because they used to clone to tempfs but then shutil.move (which copies across fs) to a data fs. Obviously for that the apps would need to be redeployed.

efiop commented 2 months ago

@mederka In that case they will both download stuff to a temporary location but then one of them will get an error that a file exists on a final os.rename, but that could've happened before too with shutil.move. What matters here is that files and repos data is guaranteed to be intact. If user logic relies on particular path then it should be able to handle EEXIST error themselves.

efiop commented 2 months ago

@badayvedat I've added a prefix, so that the files/dirs look like this: myfile.txt.tmpm_avlu_x mydir.tmplqxoo8ek, so you know what is being downloaded.