[K/N] More debugging output in HostExecutor ^KT-65113
This commit is contained in:
committed by
Space Team
parent
2c38685486
commit
f15ca6a20f
+15
-4
@@ -26,6 +26,7 @@ fun Logger.debugKt65113(msg: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class ProcessStreams(
|
class ProcessStreams(
|
||||||
|
private val logger: Logger,
|
||||||
process: Process,
|
process: Process,
|
||||||
stdin: InputStream,
|
stdin: InputStream,
|
||||||
stdout: OutputStream,
|
stdout: OutputStream,
|
||||||
@@ -42,17 +43,25 @@ class ProcessStreams(
|
|||||||
}
|
}
|
||||||
private val stdout = jobLauncher {
|
private val stdout = jobLauncher {
|
||||||
stdout.apply {
|
stdout.apply {
|
||||||
|
logger.debugKt65113("Will copy from process.inputStream to stdout")
|
||||||
copyStreams(process.inputStream, this)
|
copyStreams(process.inputStream, this)
|
||||||
|
logger.debugKt65113("Will close stdout")
|
||||||
close()
|
close()
|
||||||
}
|
}
|
||||||
|
logger.debugKt65113("Will close process.inputStream")
|
||||||
process.inputStream.close()
|
process.inputStream.close()
|
||||||
|
logger.debugKt65113("Finished stdout job")
|
||||||
}
|
}
|
||||||
private val stderr = jobLauncher {
|
private val stderr = jobLauncher {
|
||||||
stderr.apply {
|
stderr.apply {
|
||||||
|
logger.debugKt65113("Will copy from process.errorStream to stderr")
|
||||||
copyStreams(process.errorStream, this)
|
copyStreams(process.errorStream, this)
|
||||||
|
logger.debugKt65113("Will close stderr")
|
||||||
close()
|
close()
|
||||||
}
|
}
|
||||||
|
logger.debugKt65113("Will close process.errorStream")
|
||||||
process.errorStream.close()
|
process.errorStream.close()
|
||||||
|
logger.debugKt65113("Finished stderr job")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun copyStreams(from: InputStream, to: OutputStream) {
|
private fun copyStreams(from: InputStream, to: OutputStream) {
|
||||||
@@ -65,7 +74,7 @@ class ProcessStreams(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun drain(logger: Logger) {
|
suspend fun drain() {
|
||||||
// First finish passing input into the process.
|
// First finish passing input into the process.
|
||||||
logger.debugKt65113("Will join stdin")
|
logger.debugKt65113("Will join stdin")
|
||||||
stdin.join()
|
stdin.join()
|
||||||
@@ -86,11 +95,13 @@ class ProcessStreams(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun CoroutineScope.pumpStreams(
|
fun CoroutineScope.pumpStreams(
|
||||||
|
logger: Logger,
|
||||||
process: Process,
|
process: Process,
|
||||||
stdin: InputStream,
|
stdin: InputStream,
|
||||||
stdout: OutputStream,
|
stdout: OutputStream,
|
||||||
stderr: OutputStream,
|
stderr: OutputStream,
|
||||||
) = ProcessStreams(
|
) = ProcessStreams(
|
||||||
|
logger,
|
||||||
process,
|
process,
|
||||||
stdin,
|
stdin,
|
||||||
stdout,
|
stdout,
|
||||||
@@ -167,7 +178,7 @@ class HostExecutor : Executor {
|
|||||||
directory(workingDirectory)
|
directory(workingDirectory)
|
||||||
environment().putAll(request.environment)
|
environment().putAll(request.environment)
|
||||||
}.scoped(logger) { process ->
|
}.scoped(logger) { process ->
|
||||||
val streams = pumpStreams(process, request.stdin, request.stdout, request.stderr)
|
val streams = pumpStreams(logger, process, request.stdin, request.stdout, request.stderr)
|
||||||
val (isTimeout, duration) = measureTimedValue {
|
val (isTimeout, duration) = measureTimedValue {
|
||||||
!process.waitFor(request.timeout.inWholeMilliseconds, TimeUnit.MILLISECONDS)
|
!process.waitFor(request.timeout.inWholeMilliseconds, TimeUnit.MILLISECONDS)
|
||||||
}
|
}
|
||||||
@@ -175,11 +186,11 @@ class HostExecutor : Executor {
|
|||||||
logger.warning("Timeout running $commandLine in $duration")
|
logger.warning("Timeout running $commandLine in $duration")
|
||||||
streams.cancel()
|
streams.cancel()
|
||||||
process.destroyForcibly()
|
process.destroyForcibly()
|
||||||
streams.drain(logger)
|
streams.drain()
|
||||||
ExecuteResponse(null, duration)
|
ExecuteResponse(null, duration)
|
||||||
} else {
|
} else {
|
||||||
logger.info("Finished executing $commandLine in $duration exit code ${process.exitValue()}")
|
logger.info("Finished executing $commandLine in $duration exit code ${process.exitValue()}")
|
||||||
streams.drain(logger)
|
streams.drain()
|
||||||
ExecuteResponse(process.exitValue(), duration)
|
ExecuteResponse(process.exitValue(), duration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user