Skip to content

Commit bb804b7

Browse files
authored
Merge pull request #150 from andrzejressel/LockError_ZombieFound
Handle LockError.ZombieFound
2 parents 851ff76 + f0a1132 commit bb804b7

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

frontend/src/main/scala/bloop/Bloop.scala

+10-9
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,13 @@ object Bloop {
4747
private val defaultPort: Int = 8212 // 8100 + 'p'
4848
def main(args: Array[String]): Unit = {
4949
def toPortNumber(userPort: String) = Try(userPort.toInt).getOrElse(Bloop.defaultPort)
50-
val lockFilesOrHostPort = args match {
50+
val lockFilesDirOrHostPort = args match {
5151
case Array() =>
5252
val dir = bloop.io.Paths.daemonDir.underlying
53-
ensureSafeDirectoryExists(dir)
54-
val lockFiles = LockFiles.under(dir)
55-
Right(lockFiles)
53+
Right(dir)
5654
case Array(daemonArg) if daemonArg.startsWith("daemon:") =>
5755
val dir = Paths.get(daemonArg.stripPrefix("daemon:"))
58-
ensureSafeDirectoryExists(dir)
59-
val lockFiles = LockFiles.under(dir)
60-
Right(lockFiles)
56+
Right(dir)
6157
case Array(arg) =>
6258
Left((InetAddress.getLoopbackAddress(), toPortNumber(arg)))
6359
case Array(host, portStr) =>
@@ -82,15 +78,17 @@ object Bloop {
8278
truncateFilePeriodically(Paths.get(value))
8379
}
8480

85-
lockFilesOrHostPort match {
81+
lockFilesDirOrHostPort match {
8682
case Left(hostPort) =>
8783
startServer(Left(hostPort))
88-
case Right(lockFiles) =>
84+
case Right(lockFilesDir) =>
8985
val period = 3.second
9086
val attempts = 10
9187

9288
@tailrec
9389
def loop(remainingAttempts: Int): Unit = {
90+
ensureSafeDirectoryExists(lockFilesDir)
91+
val lockFiles = LockFiles.under(lockFilesDir)
9492
val res = Lock.tryAcquire(lockFiles, LockProcess.default) {
9593
startServer(Right(lockFiles.socketPaths))
9694
}
@@ -104,6 +102,9 @@ object Bloop {
104102
throw new Exception(err)
105103
case Left(_: LockError.AlreadyRunning) =>
106104
sys.exit(222) // Special exit code if a server is already running
105+
case Left(_: LockError.ZombieFound) =>
106+
Files.delete(lockFiles.pidFile)
107+
loop(remainingAttempts - 1)
107108
case Left(err: LockError.FatalError) =>
108109
throw new Exception(err)
109110
case Right(()) =>

0 commit comments

Comments
 (0)