libcni: terminate plugins on context timeout
As discussed in our maintainers meeting, we believe that libcni should handle plugin cleanup when the timeout passed by the runtime triggers. libcni should send plugins a TERM signal, wait a reasonable amount of time (a couple seconds), and then KILL plugins.
One complication is that the plugins must be part of the same process group so that (on linux) we can signal the process group and deliver the same signal to all plugins spawned from the main plugin. This could be tricky as Go doesn't easily allow changes between fork & exect.
Some references that might help: https://stackoverflow.com/questions/34730941/ensure-executables-called-in-go-process-get-killed-when-process-is-killed
We could also use syscall.SysProcAttr on Linux like so:
cmd := exec.Command("./long-process")
cmd.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,
Pgid: <some unique number we come up with?>,
}
cmd.Run()
And then we can signal the Pgid. Code for Windows is in the above stackoverflow link to do essentially the same thing.
Is Pdeathsig another way to achieve this?