Skip to content

Commit ab94e8d

Browse files
committed
Retry creating Bloop connection when multiple processes are trying it at the same time
1 parent 4ff0171 commit ab94e8d

File tree

2 files changed

+38
-31
lines changed

2 files changed

+38
-31
lines changed

modules/build/src/main/scala/scala/build/compiler/BloopCompilerMaker.scala

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package scala.build.compiler
33
import bloop.rifle.{BloopRifleConfig, BloopServer, BloopThreads}
44
import ch.epfl.scala.bsp4j.BuildClient
55

6-
import scala.build.Logger
76
import scala.build.errors.{BuildException, FetchingDependenciesError, Severity}
87
import scala.build.internal.Constants
98
import scala.build.internal.util.WarningMessages
109
import scala.build.options.BuildOptions
10+
import scala.build.{Logger, retry}
1111
import scala.concurrent.duration.DurationInt
1212
import scala.util.Try
1313

@@ -35,34 +35,36 @@ final class BloopCompilerMaker(
3535
buildOptions
3636
)
3737
case Right(config) =>
38-
val createBuildServer =
39-
() =>
40-
BloopServer.buildServer(
41-
config,
42-
"scala-cli",
43-
Constants.version,
44-
workspace.toNIO,
45-
classesDir.toNIO,
46-
buildClient,
47-
threads,
48-
logger.bloopRifleLogger
49-
)
38+
retry()(logger) {
39+
val createBuildServer =
40+
() =>
41+
BloopServer.buildServer(
42+
config,
43+
"scala-cli",
44+
Constants.version,
45+
workspace.toNIO,
46+
classesDir.toNIO,
47+
buildClient,
48+
threads,
49+
logger.bloopRifleLogger
50+
)
5051

51-
val res = Try(new BloopCompiler(createBuildServer, 20.seconds, strictBloopJsonCheck))
52-
.toEither
53-
.left.flatMap {
54-
case e if offline =>
55-
e.getCause match
56-
case _: FetchingDependenciesError =>
57-
logger.diagnostic(
58-
WarningMessages.offlineModeBloopNotFound,
59-
Severity.Warning
60-
)
61-
SimpleScalaCompilerMaker("java", Nil)
62-
.create(workspace, classesDir, buildClient, logger, buildOptions)
63-
case _ => Left(e)
64-
case e => Left(e)
65-
}.fold(t => throw t, identity)
66-
Right(res)
52+
val res = Try(new BloopCompiler(createBuildServer, 20.seconds, strictBloopJsonCheck))
53+
.toEither
54+
.left.flatMap {
55+
case e if offline =>
56+
e.getCause match
57+
case _: FetchingDependenciesError =>
58+
logger.diagnostic(
59+
WarningMessages.offlineModeBloopNotFound,
60+
Severity.Warning
61+
)
62+
SimpleScalaCompilerMaker("java", Nil)
63+
.create(workspace, classesDir, buildClient, logger, buildOptions)
64+
case _ => Left(e)
65+
case e => Left(e)
66+
}.fold(t => throw t, identity)
67+
Right(res)
68+
}
6769
case Left(ex) => Left(ex)
6870
}

modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,12 +2312,17 @@ abstract class RunTestDefinitions
23122312
os.rel / "raw.scala" -> """object Main { def main(args: Array[String]) = println(args.mkString(" ")) }"""
23132313
)
23142314
testInputs = TestInputs(input -> code)
2315+
shouldRestartBloop <- Seq(true, false)
2316+
restartBloopString = if (shouldRestartBloop) "with" else "without"
23152317
}
2316-
test(s"run several instances of $input in parallel") {
2318+
test(s"run several instances of $input in parallel ($restartBloopString restarting Bloop)") {
23172319
testInputs.fromRoot {
23182320
root =>
2321+
if (shouldRestartBloop)
2322+
os.proc(TestUtil.cli, "bloop", "exit", "--power")
2323+
.call(cwd = root)
23192324
val processes: Seq[(SubProcess, Int)] =
2320-
(0 to 20).map { i =>
2325+
(0 to 8).map { i =>
23212326
os.proc(
23222327
TestUtil.cli,
23232328
"run",

0 commit comments

Comments
 (0)