Skip to content

Commit 983a314

Browse files
authored
Retry waiting for javac under Vulpix (#17373)
2 parents d2d3da9 + 0975d29 commit 983a314

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import java.nio.file.{Files, NoSuchFileException, Path, Paths}
1212
import java.nio.charset.{Charset, StandardCharsets}
1313
import java.text.SimpleDateFormat
1414
import java.util.{HashMap, Timer, TimerTask}
15-
import java.util.concurrent.{TimeUnit, TimeoutException, Executors => JExecutors}
15+
import java.util.concurrent.{ExecutionException, TimeUnit, TimeoutException, Executors => JExecutors}
1616

1717
import scala.collection.mutable
1818
import scala.io.{Codec, Source}
@@ -494,6 +494,12 @@ trait ParallelTesting extends RunnerOrchestration { self =>
494494
.and("-d", targetDir.getPath)
495495
.withClasspath(targetDir.getPath)
496496

497+
def waitForJudiciously(process: Process): Int =
498+
try process.waitFor()
499+
catch case _: InterruptedException =>
500+
try if process.waitFor(5L, TimeUnit.MINUTES) then process.exitValue() else -2
501+
finally Thread.currentThread.interrupt()
502+
497503
def compileWithJavac(fs: Array[String]) = if (fs.nonEmpty) {
498504
val fullArgs = Array(
499505
"javac",
@@ -503,7 +509,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
503509
val process = Runtime.getRuntime.exec(fullArgs)
504510
val output = Source.fromInputStream(process.getErrorStream).mkString
505511

506-
if (process.waitFor() != 0) Some(output)
512+
if waitForJudiciously(process) != 0 then Some(output)
507513
else None
508514
} else None
509515

@@ -676,7 +682,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
676682

677683
for fut <- eventualResults do
678684
try fut.get()
679-
catch case ex: Exception =>
685+
catch
686+
case ee: ExecutionException if ee.getCause.isInstanceOf[InterruptedException] =>
687+
System.err.println("Interrupted (probably running after shutdown)")
688+
ee.printStackTrace()
689+
case ex: Exception =>
680690
System.err.println(ex.getMessage)
681691
ex.printStackTrace()
682692

0 commit comments

Comments
 (0)