Well, firstly to whom doesn’t know yet, on the 4th of December my school hosted a programming contest called ‘SCORE Compute Contest’. It is just a basic programming contest that the competitor have to write a C program to solve given problems. To make this more fun and not IOI-like, the Head make an extra system for it, but that’s out of scope for this post.

I’ve been assigned to write a contest environment (i.e. grader). It is a system, mostly web-based, for the competitor to submit their solution to be compile and grade using the restricted environment (i.e., sandbox-ed). My code was MVC-based PHP code that I use very clear variable name, for I have little time and it must have as less bugs as possible.

While I was testing it, I have fixed almost all important bug. It ran very well that time. But the problem come when the real competition was started. Some solution putting the grader in full-locked situation! I don’t know what caused that, and I’m very stressed, so I blame the sandbox which I use the Moe Contest Environment’s. So far, our Head have a solution, and therefore the contest end pretty well.

After many hours of sleep, my head went bright and I realise what caused it. Guess guess guess…. It is the IPC!?! Old way I use is to pipe the sandbox process’s output through streams. I carefully check that I have already closed all stream before terminating the process (proc_close(), my grader is written in PHP). But somehow I realise, that IPC may caused deadlock if not very well implemented. And I’m not sure that the wrapper for piping process’s I/O I quickly cook was really bug-free. So far yesterday I come back to the grader and change from piping through the stream to piping to filesystem. And it works!

UPDATE: The working system I wrote can be found at http://napv-ce.googlecode.com/ There will be no more update to it.