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

Add retry to the rt.jar copying stuff #4004

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 32 additions & 14 deletions main/api/src/mill/api/ClassLoader.scala
Original file line number Diff line number Diff line change
@@ -2,10 +2,10 @@ package mill.api

import java.net.{URL, URLClassLoader}

import java.nio.file.FileAlreadyExistsException
import java.nio.file.{FileAlreadyExistsException, FileSystemException}

import mill.java9rtexport.Export
import scala.util.Try
import scala.util.{Properties, Try}

/**
* Utilities for creating classloaders for running compiled Java/Scala code in
@@ -78,19 +78,37 @@ object ClassLoader {
if (java9OrAbove) {
val java90rtJar = ctx.home / Export.rtJarName
if (!os.exists(java90rtJar)) {
Try {
os.copy(os.Path(Export.rt()), java90rtJar, createFolders = true)
}.recoverWith { case e: FileAlreadyExistsException =>
// some race?
if (os.exists(java90rtJar) && PathRef(java90rtJar) == PathRef(os.Path(Export.rt()))) Try {
// all good
()
// Time between retries should go from 100 ms to around 10s, which should
// leave plenty of time for another process to write fully this 50+ MB file
val retry = Retry(
count = 7,
backoffMillis = 100,
filter = {
case (_, _: FileSystemException) if Properties.isWin => true
case _ => false
}
else Try {
// retry
os.copy(os.Path(Export.rt()), java90rtJar, replaceExisting = true, createFolders = true)
}
}.get
)
retry {
Try {
os.copy(os.Path(Export.rt()), java90rtJar, createFolders = true)
}.recoverWith { case e: FileAlreadyExistsException =>
// some race?
if (os.exists(java90rtJar) && PathRef(java90rtJar) == PathRef(os.Path(Export.rt())))
Try {
// all good
()
}
else Try {
// retry
os.copy(
os.Path(Export.rt()),
java90rtJar,
replaceExisting = true,
createFolders = true
)
}
}.get
}
}
urls :+ java90rtJar.toIO.toURI().toURL()
} else {