Fix ThreadDeath exception on stopping daemon thread
#KT-30086 fixed
This commit is contained in:
+23
-22
@@ -388,28 +388,29 @@ object KotlinCompilerClient {
|
|||||||
isEchoRead.acquire()
|
isEchoRead.acquire()
|
||||||
|
|
||||||
val stdoutThread =
|
val stdoutThread =
|
||||||
thread {
|
thread {
|
||||||
try {
|
try {
|
||||||
daemon.inputStream
|
daemon.inputStream
|
||||||
.reader()
|
.reader()
|
||||||
.forEachLine {
|
.forEachLine {
|
||||||
if (it == COMPILE_DAEMON_IS_READY_MESSAGE) {
|
if (Thread.currentThread().isInterrupted) return@forEachLine
|
||||||
reportingTargets.report(DaemonReportCategory.DEBUG, "Received the message signalling that the daemon is ready")
|
if (it == COMPILE_DAEMON_IS_READY_MESSAGE) {
|
||||||
isEchoRead.release()
|
reportingTargets.report(DaemonReportCategory.DEBUG, "Received the message signalling that the daemon is ready")
|
||||||
return@forEachLine
|
isEchoRead.release()
|
||||||
}
|
return@forEachLine
|
||||||
else {
|
} else {
|
||||||
reportingTargets.report(DaemonReportCategory.INFO, it, "daemon")
|
reportingTargets.report(DaemonReportCategory.INFO, it, "daemon")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (_: Throwable) {
|
||||||
finally {
|
// Ignore, assuming all exceptions as interrupt exceptions
|
||||||
daemon.inputStream.close()
|
} finally {
|
||||||
daemon.outputStream.close()
|
daemon.inputStream.close()
|
||||||
daemon.errorStream.close()
|
daemon.outputStream.close()
|
||||||
isEchoRead.release()
|
daemon.errorStream.close()
|
||||||
}
|
isEchoRead.release()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
// trying to wait for process
|
// trying to wait for process
|
||||||
val daemonStartupTimeout = System.getProperty(COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY)?.let {
|
val daemonStartupTimeout = System.getProperty(COMPILE_DAEMON_STARTUP_TIMEOUT_PROPERTY)?.let {
|
||||||
@@ -444,7 +445,7 @@ object KotlinCompilerClient {
|
|||||||
// assuming that all important output is already done, the rest should be routed to the log by the daemon itself
|
// assuming that all important output is already done, the rest should be routed to the log by the daemon itself
|
||||||
if (stdoutThread.isAlive) {
|
if (stdoutThread.isAlive) {
|
||||||
// TODO: find better method to stop the thread, but seems it will require asynchronous consuming of the stream
|
// TODO: find better method to stop the thread, but seems it will require asynchronous consuming of the stream
|
||||||
stdoutThread.stop()
|
stdoutThread.interrupt()
|
||||||
}
|
}
|
||||||
reportingTargets.out?.flush()
|
reportingTargets.out?.flush()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user