cni icon indicating copy to clipboard operation
cni copied to clipboard

libcni: terminate plugins on context timeout

Open dcbw opened this issue 6 years ago • 1 comments

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.

dcbw avatar Jul 03 '19 16:07 dcbw

Is Pdeathsig another way to achieve this?

bboreham avatar Dec 22 '20 15:12 bboreham