MinecraftForge / ForgeGradle

Minecraft mod development framework used by Forge and FML for the gradle build system
GNU Lesser General Public License v2.1
509 stars 437 forks source link

[FG5] downloadAssets sometimes fails due to a race condition #800

Closed shartte closed 3 years ago

shartte commented 3 years ago

Edit: After looking at it again more closely, this is yet another race condition, similar to #755, but this time affecting Vanilla assets.

This happens because minecraft/icons/minecraft.icns and icons/minecraft.icns both use the same remote path. The download task will download the same file twice, and if it's unlucky, two threads will be writing to the same file on disk, resulting in a corrupt download.

~~Sometimes asset just fail to download correctly. Since it involves remote access, this can be expected. On CI/CD servers this can be very annoying since it leads to false-positive build failures.~~

It would be nice for one of the following:

Example issue from a GitHub Actions build:

Downloading: https://resources.download.minecraft.net/99/991b421dfd401f115241601b2b373140a8d78572 Asset: icons/minecraft.icns
Downloading: https://resources.download.minecraft.net/99/991b421dfd401f115241601b2b373140a8d78572 Asset: minecraft/icons/minecraft.icns
icons/minecraft.icns Hash failed.
minecraft/icons/minecraft.icns Failed.

java.io.FileNotFoundException: /home/runner/.gradle/caches/forge_gradle/assets/objects/99/991b421dfd401f115241601b2b373140a8d78572 (No such file or directory)
    at java.io.FileInputStream.open0(Native Method)
    at java.io.FileInputStream.open(FileInputStream.java:195)
    at java.io.FileInputStream.<init>(FileInputStream.java:138)
    at net.minecraftforge.gradle.common.util.HashFunction.hash(HashFunction.java:63)
    at net.minecraftforge.gradle.common.task.DownloadAssets.lambda$run$0(DownloadAssets.java:70)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
shartte commented 3 years ago

Fixed by #801