tasks: fix update failed notification

https://forum.cloudron.io/topic/13408/update-to-cloudron-8.3-error

We get a Task xx crashed with code null in the notification.

The crux of the issue is that we use KillMode=control-group. This ends
up sending SIGTERM signal to box code and all the sudo in parallel. The box
code then sees the sudo die and records the task as failed.

To fix, we switch to KillMode=mixed. This gives box code a chance to handle SIGTERM
first. It cleans out its task list and kills all the sudo.
This commit is contained in:
Girish Ramakrishnan
2025-06-17 22:30:34 +02:00
parent ca25c6075b
commit fb39aa32bb
7 changed files with 35 additions and 34 deletions

View File

@@ -159,12 +159,11 @@ function sudo(tag, args, options, callback) {
// sudo does not forward signals when the originator comes from the same process group. recently, there has been a change where it will
// forward signals as long as sudo or the command is not the group leader (https://www.sudo.ws/repos/sudo/rev/d1bf60eac57f)
// for us, this means that calling kill from this node process doesn't work since it's in the same group (and ubuntu 22 doesn't have the above fix).
// the workaround is to invoke a kill from a different process group and this is done by starting detached
// the workaround is to invoke a kill from a different process group and this is done by starting detached . negative pid mean to group
// another idea is: use "ps --pid cp.pid -o pid=" to get the pid of the command and then send it signal directly
// ...despite all this hackery this only appears to work for sudo tail and not for sudo systemd-run . go figure.
cp.terminate = function () {
cp.terminated = true; // hint for better debug message in 'exit'
child_process.spawn('kill', ['-SIGTERM', cp.pid], { detached: true }, (error) => { if (error) debug(`${tag} could not terminate`, error); });
child_process.spawn('kill', ['-SIGKILL', -cp.pid], { detached: true }, (error) => { if (error) debug(`${tag} could not terminate`, error); });
};
cp.stdin.end();