Skip to content

Commit

Permalink
Disarm timer in runguard after child has exited. (#2157)
Browse files Browse the repository at this point in the history
If we would not disarm the timer, there is a possibility that the timer
sends us a SIGALRM while we are still busy with cleaning the sandbox up.

What you observe in these cases is a judging with wall time well below
the time limit is judged as TLE, e.g.
```
Timelimit exceeded.
runtime: 0.288s cpu, 0.302s wall
memory used: 26066944 bytes
********** runguard stderr follows **********
/opt/domjudge/bin/runguard: warning: timelimit exceeded (hard wall time): aborting command
```

In practice, we saw the behavior happening when running many
judgedaemons and domserver on a single machine while rejudging the whole
contest (i.e.  under quite high load). In that case, the call
`cgroup_delete_cgroup_ext` did sometimes hang for multiple seconds.

For easy reproducibility, you can also add an artificial delay in the
clean up code, e.g. by adding something like:
```
const struct timespec artificial_delay = { 10, 0 };
nanosleep(&artificial_delay, NULL);
```
  • Loading branch information
meisterT authored Sep 30, 2023
1 parent 0c5bf5e commit 85e8f9e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion judge/runguard.c
Original file line number Diff line number Diff line change
Expand Up @@ -1428,8 +1428,23 @@ int main(int argc, char **argv)
} else {
exitcode = WEXITSTATUS(status);
}
verbose("child exited with exit code %d", exitcode);

check_remaining_procs();
if ( use_walltime ) {
/* Disarm timer we set previously so if any of the
* clean-up steps below are slow we are not mistaking
* this for a wall-time timeout. */
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = 0;
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = 0;

if ( setitimer(ITIMER_REAL,&itimer,NULL)!=0 ) {
error(errno,"disarming timer");
}
}

check_remaining_procs();

double cputime = -1;
output_cgroup_stats(&cputime);
Expand Down

0 comments on commit 85e8f9e

Please sign in to comment.