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

Try harder to deal with stuck index generation #11098

Merged
merged 1 commit into from
Sep 17, 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
24 changes: 17 additions & 7 deletions project/DistributionPackage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import sbt.io.syntax.fileToRichFile
import sbt.util.{CacheStore, CacheStoreFactory, FileInfo, Tracked}

import scala.sys.process._

import org.enso.build.WithDebugCommand

import java.nio.file.Paths
import scala.util.Try

object DistributionPackage {
Expand Down Expand Up @@ -257,12 +257,20 @@ object DistributionPackage {
// Poor man's solution to stuck index generation
val GENERATING_INDEX_TIMEOUT = 60 * 2 // 2 minutes
var current = 0
while (runningProcess.isAlive()) {
var timeout = false
while (runningProcess.isAlive() && !timeout) {
if (current > GENERATING_INDEX_TIMEOUT) {
java.lang.System.err
.println("Reached timeout when generating index. Terminating...")
try {
val pidOfProcess = pid(runningProcess)
val javaHome = System.getProperty("java.home")
val jstack =
if (javaHome == null) "jstack"
else
Paths.get(javaHome, "bin", "jstack").toAbsolutePath.toString
val in = java.lang.Runtime.getRuntime
.exec(Array("jstack", pidOfProcess.toString))
.exec(Array(jstack, pidOfProcess.toString))
.getInputStream

System.err.println(IOUtils.toString(in, "UTF-8"))
Expand All @@ -271,18 +279,20 @@ object DistributionPackage {
java.lang.System.err
.println("Failed to get threaddump of a stuck process", e);
} finally {
timeout = true
runningProcess.destroy()
}
} else {
Thread.sleep(1000)
current += 1
}
}
if (timeout) {
throw new RuntimeException(
s"TIMEOUT: Failed to compile $libName in $GENERATING_INDEX_TIMEOUT seconds"
)
}
if (runningProcess.exitValue() != 0) {
if (current > GENERATING_INDEX_TIMEOUT)
throw new RuntimeException(
s"TIMEOUT: Failed to compile $libName in $GENERATING_INDEX_TIMEOUT seconds"
)
throw new RuntimeException(s"Cannot compile $libName.")
}
} else {
Expand Down
Loading