Skip to content

Commit 6f7c1f0

Browse files
committed
properly differentiate between OOM, out of disk and tiumeout
1 parent 5027597 commit 6f7c1f0

File tree

1 file changed

+47
-15
lines changed

1 file changed

+47
-15
lines changed

src/main/kotlin/ch/uzh/ifi/access/service/CourseService.kt

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,22 @@ class CourseService(
382382
)
383383
val command = (
384384
"""
385+
# copy submitted files to tmpfs
385386
/bin/cp -R /submission/* /workspace/;
387+
# run command (the cwd is set to /workspace already)
386388
${task.formCommand(submission.command!!)} &> logs.txt;
389+
# remember the command's exit code
390+
exit_code=${'$'}?;
391+
# write results and logs to submission volume
387392
/bin/cp /workspace/grade_results.json /submission/;
388393
/bin/cp /workspace/logs.txt /submission/;
394+
# check if the tmpfs is full and if so, return 201, otherwise return command status code
395+
USAGE=${'$'}(df -h | grep /workspace | awk '{print ${'$'}5}' | sed 's/%//')
396+
if [ "${'$'}USAGE" -eq 100 ]; then
397+
exit 201
398+
else
399+
exit ${'$'}exit_code;
400+
fi
389401
"""
390402
)
391403
val container = containerCmd
@@ -399,7 +411,6 @@ ${task.formCommand(submission.command!!)} &> logs.txt;
399411
.withBinds(Bind.parse("$submissionDir:/submission"))
400412
.withAutoRemove(true)
401413
).exec()
402-
dockerClient.startContainerCmd(container.id).exec()
403414

404415
val scheduler = Executors.newScheduledThreadPool(1)
405416
var killedContainer = false
@@ -412,6 +423,7 @@ ${task.formCommand(submission.command!!)} &> logs.txt;
412423
logger.debug { "Container ${container.id} probably stopped already"}
413424
}
414425
}, task.timeLimit.coerceAtMost(180).toLong(), TimeUnit.SECONDS)
426+
dockerClient.startContainerCmd(container.id).exec()
415427

416428
val statusCode = dockerClient.waitContainerCmd(container.id)
417429
.exec(WaitContainerResultCallback())
@@ -422,21 +434,41 @@ ${task.formCommand(submission.command!!)} &> logs.txt;
422434
submission.logs = readLogsFile(submissionDir)
423435
logger.debug { "Submission $submissionDir finished with statusCode $statusCode"}
424436
if (newSubmission.isGraded) {
425-
// 137 means "out of memory"
426-
val results = if (statusCode == 137) {
427-
logger.debug { "Submission $submissionDir exit code is 137"}
428-
if (killedContainer) {
429-
Results(0.0, listOf("Your solution ran out of time. Check for infinite loops and ensure your solution is sufficiently fast even for challenging problem parameters."))
437+
val results = when (statusCode) {
438+
// out of memory
439+
137 -> {
440+
logger.debug { "Submission $submissionDir exit code is 137" }
441+
if (killedContainer) {
442+
logger.debug { "Submission $submissionDir killed due to timeout" }
443+
Results(
444+
0.0,
445+
listOf("Your solution ran out of time. Check for infinite loops and ensure your solution is sufficiently fast even for challenging problem parameters.")
446+
)
447+
} else {
448+
logger.debug { "Submission $submissionDir out of memory" }
449+
Results(
450+
0.0,
451+
listOf("Your solution ran out of memory. Make sure you aren't creating gigantic data structures.")
452+
)
453+
}
430454
}
431-
else {
432-
Results(0.0, listOf("Your solution ran out of memory. Make sure you aren't creating gigantic data structures."))
455+
// out of tmpfs disk space
456+
201 -> {
457+
Results(
458+
0.0,
459+
listOf("Your solution wrote too much data, either to files, or by printing to the command line. Are you printing in an infinite loop?")
460+
)
433461
}
434-
}
435-
else {
436-
try {
437-
readResultsFile(submissionDir)
438-
} catch (e: NoSuchFileException) {
439-
Results(0.0, listOf("Your solution generated too much data written to files or printed to the command line (printing in an infinite loop?)"))
462+
// none of the above, hopefully there are grading results
463+
else -> {
464+
try {
465+
readResultsFile(submissionDir)
466+
} catch (e: NoSuchFileException) {
467+
logger.debug { "Submission $submissionDir no grade_results.json" }
468+
Results(null,
469+
listOf("No grading results. Please report this as a bug and provide as much detail as possible.")
470+
)
471+
}
440472
}
441473
}
442474
newSubmission.parseResults(results)
@@ -446,7 +478,7 @@ ${task.formCommand(submission.command!!)} &> logs.txt;
446478
}
447479
}
448480
} catch (e: Exception) {
449-
newSubmission.output = "Uncaught ${e::class.simpleName}: ${e.message}. Please report this as a bug (providing as much detail as possible)."
481+
newSubmission.output = "Uncaught ${e::class.simpleName}: ${e.message}. Please report this as a bug and provide as much detail as possible."
450482
}
451483
submissionRepository.save(newSubmission)
452484
}

0 commit comments

Comments
 (0)