I am creating an AI competition where competitors can upload their AIs (node servers) to our node server and we take in their code and run it in an automated fashion.
On first code upload, I use child_process.spawn()
to run node server.js xxx
where xxx is their port. I store the spawned child as well as the competitor id in memory. When they upload a second time, I search through my stored child processes by competitor id and call process.kill(pid, 'SIGKILL')
on the process.
On each spawned child I have set up child.on('close', callback)
. On this callback, I want to delete their code directory where I uploaded their node server to and then copy in their new code and spin up a node server again. However, I cannot delete the code directory because it is still in use (I get an EBUSY error), I think I am not killing the node process correctly.
Is this an okay approach? If so, what am I doing wrong?