Skip to content

Commit

Permalink
Do not lose exception info in bloop connection check
Browse files Browse the repository at this point in the history
Exceptions in Operations.startServer.check0 were ignored (not passed
to the promise). In case of a recurringe exception, the result
presented to the user was just timeout.

After this change, if timeout occurs, the method fills promise with
the last, or almost last exception.
  • Loading branch information
tpasternak committed Jan 18, 2022
1 parent affe15b commit 9f00216
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ object BloopServer {
bloopVersion,
bloopJava
)
Await.result(fut, 30.seconds)
Await.result(fut, config.startCheckTimeout + 30.seconds)
}
def exitBloop() = BloopRifle.exit(config, workdir, logger)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,29 @@ object Operations {
def check0(f: => ScheduledFuture[_]): Runnable = {
val start = System.currentTimeMillis()
() =>
val completionOpt =
if (!p.isAlive())
Some(Failure(new Exception("Server didn't start")))
else if (check(address, logger))
Some(Success(()))
else if (timeout.isFinite && System.currentTimeMillis() - start > timeout.toMillis)
Some(Failure(new Exception(s"Server didn't start after $timeout ms")))
else
None

for (completion <- completionOpt) {
promise.tryComplete(completion)
f.cancel(false)
try {
val completionOpt =
if (!p.isAlive())
Some(Failure(new Exception("Server didn't start")))
else if (check(address, logger))
Some(Success(()))
else if (timeout.isFinite && System.currentTimeMillis() - start > timeout.toMillis)
Some(Failure(new Exception(s"Server didn't start after $timeout ms")))
else
None

for (completion <- completionOpt) {
promise.tryComplete(completion)
f.cancel(false)
}
}
catch {
case t: Throwable =>
if (timeout.isFinite && System.currentTimeMillis() - start > timeout.toMillis) {
promise.tryFailure(t)
f.cancel(false)
}
throw t
}
}

Expand Down

0 comments on commit 9f00216

Please sign in to comment.