Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions judge/judgedaemon.main.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,19 @@
}
}

class JudgeDaemon

Check warning on line 136 in judge/judgedaemon.main.php

View workflow job for this annotation

GitHub Actions / phpcs

Possible parse error: class missing opening or closing brace

Check warning on line 136 in judge/judgedaemon.main.php

View workflow job for this annotation

GitHub Actions / phpcs

Possible parse error: class missing opening or closing brace
{
private const FD_STDIN = 0;

Check failure on line 138 in judge/judgedaemon.main.php

View workflow job for this annotation

GitHub Actions / phpcs

Line indented incorrectly; expected 0 spaces, found 4
private const FD_STDOUT = 1;

Check failure on line 139 in judge/judgedaemon.main.php

View workflow job for this annotation

GitHub Actions / phpcs

Line indented incorrectly; expected 0 spaces, found 4
private const FD_STDERR = 2;

Check failure on line 140 in judge/judgedaemon.main.php

View workflow job for this annotation

GitHub Actions / phpcs

Line indented incorrectly; expected 0 spaces, found 4

// Exit codes from compare scripts
private const COMPARE_EXITCODE_CORRECT = 42;

Check failure on line 143 in judge/judgedaemon.main.php

View workflow job for this annotation

GitHub Actions / phpcs

Line indented incorrectly; expected 0 spaces, found 4
private const COMPARE_EXITCODE_WRONG_ANSWER = 43;

Check failure on line 144 in judge/judgedaemon.main.php

View workflow job for this annotation

GitHub Actions / phpcs

Line indented incorrectly; expected 0 spaces, found 4

private const EXTERNAL_IDENTIFIER_REGEX = '/^[a-zA-Z0-9_.-]+$/';

Check failure on line 146 in judge/judgedaemon.main.php

View workflow job for this annotation

GitHub Actions / phpcs

Line indented incorrectly; expected 0 spaces, found 4

private static ?JudgeDaemon $instance = null;

Check failure on line 148 in judge/judgedaemon.main.php

View workflow job for this annotation

GitHub Actions / phpcs

Line indented incorrectly; expected 0 spaces, found 4

/**
* @var array{id: string, user: string, pass: string, url: string,
Expand All @@ -153,10 +153,10 @@
* ch?: CurlHandle|false
* }|null
*/
private ?array $endpoint = null;

Check failure on line 156 in judge/judgedaemon.main.php

View workflow job for this annotation

GitHub Actions / phpcs

Line indented incorrectly; expected 0 spaces, found 4
/** @var array<string, mixed> */
private array $domjudge_config = [];

Check failure on line 158 in judge/judgedaemon.main.php

View workflow job for this annotation

GitHub Actions / phpcs

Line indented incorrectly; expected 0 spaces, found 4
private string $myhost;

Check failure on line 159 in judge/judgedaemon.main.php

View workflow job for this annotation

GitHub Actions / phpcs

Line indented incorrectly; expected 0 spaces, found 4
private int $verbose = LOG_INFO;
private ?string $daemonid = null;
/** @var array<string, bool|string> */
Expand Down Expand Up @@ -343,6 +343,15 @@
$this->loop();
}

private function handleMetaInternalError(int $judgetaskid, array $metadata): void
{
// Unexpected situation during setup of the submission, so disable the judgehost itself as no
// submission should be able to break runguard
// TODO: Add suggestion for what to do in case this submission breaks for all judgehosts, violating above statement
// would we advice ignoring the submission or changing the database etc.
$this->disable('judgehost', 'hostname', $this->myhost, "Running submission caused a crash/error in runguard: " . $metadata['internal-error'], $judgetaskid);
}

private function initialize(): void
{
// Set umask to allow group and other access, as this is needed for the
Expand Down Expand Up @@ -1724,7 +1733,8 @@
$compare_runpath,
$compare_args,
array $run_config,
array $compare_config
array $compare_config,
?int $judgetaskid = null
) : Verdict {
// Record some state so that we can properly reset it later in the finally block
$oldCwd = getcwd();
Expand Down Expand Up @@ -1779,7 +1789,7 @@

foreach ([
'system.out', # Judging system output (info/debug/error)
'program.out', 'program.err', # Program output and stderr (for extra information)
'program.out', 'program.err', # Program output and stderr (for extra information)
'program.meta', 'runguard.err', # Metadata and runguard stderr
'compare.meta', 'compare.err' # Compare runguard metadata and stderr
] as $file) {
Expand Down Expand Up @@ -2014,10 +2024,14 @@
}

logmsg(LOG_DEBUG, "checking compare script exit status: $exitcode");
$compare_meta_raw = file_get_contents("compare.meta");
$compare_tmp = is_readable("compare.tmp") ? file_get_contents("compare.tmp") : "";
$compareTimedOut = (bool)preg_match('/time-result: .*timelimit/', $compare_meta_raw);
if ($compareTimedOut) {
$compare_meta_ini = $this->readMetadata('compare.meta');
$compareTimedOut = false;
if (isset($compare_meta_ini['internal-error'])) {
$this->handleMetaInternalError($description, $judgetaskid, $compare_meta_ini);
return Verdict::INTERNAL_ERROR;
} elseif ($compare_meta_ini['time-result'] === 'timelimit') {
$compareTimedOut = true;
logmsg(LOG_ERR, "Comparing aborted after the script timelimit of %s seconds, compare script output:\n%s", $scripttimelimit, $compare_tmp);
}

Expand All @@ -2038,13 +2052,16 @@
}
logmsg(LOG_DEBUG, "checking program exit status");
$program_meta_ini = $this->readMetadata('program.meta');
if (isset($program_meta_ini['internal-error'])) {
$this->handleMetaInternalError($judgetaskid, $program_meta_ini);
return Verdict::INTERNAL_ERROR;
}
logmsg(LOG_DEBUG, "parsed program meta: " . var_export($program_meta_ini, true));
$resourceInfo = "\nruntime: "
. $program_meta_ini['cpu-time'] . 's cpu, '
. $program_meta_ini['wall-time'] . "s wall\n"
. 'memory: ' . $program_meta_ini['memory-bytes'] . ' bytes';

$compare_meta_ini = $this->readMetadata('compare.meta');
logmsg(LOG_DEBUG, "parsed compare meta: " . var_export($compare_meta_ini, true));

$programOutSize = filesize("program.out");
Expand Down Expand Up @@ -2239,14 +2256,28 @@
$compare_runpath,
$compare_config['compare_args'],
$run_config,
$compare_config
$compare_config,
$judgeTask['judgetaskid']
);

$result = str_replace('_', '-', strtolower($verdict->name));
if ($result === 'internal-error') {
// Don't disable anything as it's unclear how problematic the error is
return false;
}

// Try to read metadata from file
$runtime = null;
$metadata = $this->readMetadata($passdir . '/program.meta');
if (isset($metadata['internal-error'])) {
// This should already be handled in `testcaseRunInternal`
<<<<<<< HEAD
$this->handleProgramInternalError($judgetaskid, $metadata);
=======
$this->handleMetaInternalError($judgetaskid, $program_meta_ini);
>>>>>>> 9d7d39a23 (Handle internal-errors in compare.meta)
return false;
}

if (isset($metadata['time-used']) && array_key_exists($metadata['time-used'], $metadata)) {
$runtime = $metadata[$metadata['time-used']];
Expand Down
Loading