Skip to content

Commit 4a8915d

Browse files
authored
Verify that child processes start correctly (#58)
* Verify that child processes start correctly * Remove todo * Update copyrights * Make ktlint happy
1 parent bca28ef commit 4a8915d

File tree

2 files changed

+24
-4
lines changed
  • launcher/src/main/kotlin/org/sourcegrade/jagr/launcher/executor
  • src/main/kotlin/org/sourcegrade/jagr

2 files changed

+24
-4
lines changed

launcher/src/main/kotlin/org/sourcegrade/jagr/launcher/executor/ProcessWorker.kt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Jagr - SourceGrade.org
3-
* Copyright (C) 2021-2024 Alexander Städing
4-
* Copyright (C) 2021-2024 Contributors
3+
* Copyright (C) 2021-2025 Alexander Städing
4+
* Copyright (C) 2021-2025 Contributors
55
*
66
* This program is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Affero General Public License as published by
@@ -59,8 +59,25 @@ class ProcessWorker(
5959
status = WorkerStatus.READY
6060
}
6161

62+
/**
63+
* Ensures that [process] has been initialized correctly.
64+
*
65+
* This should be only called once per process.
66+
*/
67+
private fun checkBoot() {
68+
// wait for child process to start
69+
val line = process.inputReader(Charsets.UTF_8).readLine()
70+
if (line != MARK_CHILD_BOOT) {
71+
throw IllegalStateException(
72+
"Child process did not start correctly:\n" +
73+
process.errorStream.reader().readText(),
74+
)
75+
}
76+
}
77+
6278
override fun assignJob(job: GradingJob) {
6379
check(this.job == null) { "Worker already has a job!" }
80+
checkBoot()
6481
status = WorkerStatus.RUNNING
6582
coroutineScope.launch {
6683
try {
@@ -141,5 +158,6 @@ class ProcessWorker(
141158
companion object {
142159
const val MARK_LOG_MESSAGE_BYTE = 2
143160
const val MARK_RESULT_BYTE = 7
161+
const val MARK_CHILD_BOOT = "jagr-child-boot"
144162
}
145163
}

src/main/kotlin/org/sourcegrade/jagr/Main.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Jagr - SourceGrade.org
3-
* Copyright (C) 2021-2022 Alexander Staeding
4-
* Copyright (C) 2021-2022 Contributors
3+
* Copyright (C) 2021-2025 Alexander Städing
4+
* Copyright (C) 2021-2025 Contributors
55
*
66
* This program is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Affero General Public License as published by
@@ -27,6 +27,7 @@ import com.github.ajalt.clikt.parameters.types.choice
2727
import org.sourcegrade.jagr.launcher.env.Environment
2828
import org.sourcegrade.jagr.launcher.env.Jagr
2929
import org.sourcegrade.jagr.launcher.env.logger
30+
import org.sourcegrade.jagr.launcher.executor.ProcessWorker
3031

3132
fun main(vararg args: String) {
3233
try {
@@ -53,6 +54,7 @@ class MainCommand : CliktCommand() {
5354

5455
override fun run() {
5556
if (child) {
57+
println(ProcessWorker.MARK_CHILD_BOOT)
5658
Environment.initializeChildProcess()
5759
ChildProcGrading().grade()
5860
} else {

0 commit comments

Comments
 (0)