Skip to content

Defend against reading before runguard is done writing#3482

Closed
vmcj wants to merge 1 commit intoDOMjudge:mainfrom
vmcj:runguard_exit_timeout
Closed

Defend against reading before runguard is done writing#3482
vmcj wants to merge 1 commit intoDOMjudge:mainfrom
vmcj:runguard_exit_timeout

Conversation

@vmcj
Copy link
Member

@vmcj vmcj commented Feb 28, 2026

I was testing for another PR where I kill the judgedaemon after 30s (timeout 30s ./bin/judgedaemon -n2), I suspect the judgedaemon gets a signal here, sends it to runguard which kills the submission but is not done writing yet, the judgedaemon already starts reading the file which is still empty (verified that by outputting it in the judgedaemon) but has values after the judgedaemon exits.

This check should fix that racecondition but as this is such a specific case I'm not sure if we want to slow ourselves down by reading such files twice?

@vmcj vmcj requested a review from meisterT February 28, 2026 16:17
@meisterT
Copy link
Member

meisterT commented Mar 1, 2026

I don't believe the race condition as you describe it can exist. Please let me know what I am missing.

The judgedaemon calls runguard in synchronous fashion, should never do it asynchronously. In runCommandSafe we call proc_close in https://github.com/DOMjudge/domjudge/blob/main/judge/judgedaemon.main.php#L1044. According to https://www.php.net/manual/en/function.proc-close.php:

proc_close() waits for the process to terminate, and returns its exit code

So, we wait until runguard is completely done with its execution before continueing with other code flow within judgedaemon. That means it is guaranteed that the runguard has completed all of its work before calling parseMetadata. Of course runguard can crash (or be killed), but also means that whenever we receive back control, it cannot write more data to the metadata file.

@vmcj vmcj closed this Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants