`rclone serve restic` processes left behind
I have noticed that after playing with rustic I always have rclone serve restic processes left behind and running, e.g.:
$ ps -ef | grep rclone
501 25941 1 0 Fri05PM ?? 0:13.96 rclone serve restic onedrive:restic-VM --addr localhost:0
501 5407 1 0 Thu09PM ttys003 2:34.60 rclone serve restic OD01-ENC:restic-test --addr localhost:0
501 12210 1 0 Fri07AM ttys003 0:15.61 rclone serve restic OD01-ENC:restic-test --addr localhost:0
It would mean that sometimes when rustic is terminated it does not stop rclone instance it is using.
I have not identified yet reproducible conditions but I see it daily so it is not something exceptional.
duplicate of https://github.com/rustic-rs/rustic_core/issues/22
Actually I cannot yet explain why this is happening. But I can confirm that I also had left-over rclone instances. But it seem I'm not having them for my regular scheduled backups. So my theory is that either backup is not affected or that systemd-scheduled runs are not affected...
Actually, I thought that when the rclone backend is dropped, it will always call a kill on the created subprocess. Technically the Child process is wrapped in an Arc and kill is called just before the containing Child is dropped. For panicking rustic runs, this could cause left-over child processes. But it seems, we also have this for normally terminating runs...Maybe the Arc gets never dropped? In this case, https://github.com/rustic-rs/rustic_core/pull/73 might help as with this PR, a backend no longer needs to be Copy and we can remove the Arc.
About systemd runs. IIRC, systemd would take care about subprocesses and also kill them - this would explain why this is not observable with systemd.
I did some other tests and can say that I can reproduce the behavior when I manually run rustic check.
Now I'll try if #73 fixed that...
Unfortunately, #73 didn't fix it.. I'll have to take a deeper look into where things could go wrong...
I think I found the reason, see https://github.com/rustic-rs/rustic_core/issues/22
closed via https://github.com/rustic-rs/rustic_core/pull/139
Caught this problem on version rustic v0.10.0 Added timeout wrapper to temp fix this. UPD Which doesn't help.
[root@apitest ~]# ps -ef | grep rclone
root 30883 1 0 04:00 ? 00:00:10 rclone serve restic --addr localhost:0 mega:/backups
root 32157 1 0 07:00 ? 00:00:09 rclone serve restic --addr localhost:0 mega:/backups
root 33349 1 0 09:00 ? 00:00:08 rclone serve restic --addr localhost:0 mega:/backups
root 33974 1 0 10:00 ? 00:00:06 rclone serve restic --addr localhost:0 mega:/backups
root 34394 1 0 11:00 ? 00:00:06 rclone serve restic --addr localhost:0 mega:/backups
root 35410 1 0 13:00 ? 00:00:04 rclone serve restic --addr localhost:0 mega:/backups
root 36313 1 0 14:00 ? 00:00:03 rclone serve restic --addr localhost:0 mega:/backups
root 37420 1 0 15:00 ? 00:00:02 rclone serve restic --addr localhost:0 mega:/backups
root 39375 39046 0 16:53 pts/0 00:00:00 grep --color=auto rclone
UPD
Setting rclone-command = "rclone serve restic --timeout 10m --addr localhost:0" also doesn't fix this.
[root@apitest ~]# ps -ef | grep rclone
root 49836 1 0 Oct30 ? 00:00:13 rclone serve restic --timeout 10m --addr localhost:0 mega:/backups
root 50548 1 0 Oct30 ? 00:00:11 rclone serve restic --timeout 10m --addr localhost:0 mega:/backups
root 51322 1 0 Oct30 ? 00:00:12 rclone serve restic --timeout 10m --addr localhost:0 mega:/backups
root 51603 1 0 Oct30 ? 00:00:14 rclone serve restic --timeout 10m --addr localhost:0 mega:/backups
root 51936 1 0 Oct30 ? 00:00:13 rclone serve restic --timeout 10m --addr localhost:0 mega:/backups
root 52334 1 0 Oct30 ? 00:00:10 rclone serve restic --timeout 10m --addr localhost:0 mega:/backups
root 52811 1 0 Oct30 ? 00:00:09 rclone serve restic --timeout 10m --addr localhost:0 mega:/backups
root 53271 1 0 Oct30 ? 00:00:10 rclone serve restic --timeout 10m --addr localhost:0 mega:/backups
root 54434 1 0 Oct30 ? 00:00:07 rclone serve restic --timeout 10m --addr localhost:0 mega:/backups
root 55960 1 0 Oct30 ? 00:00:05 rclone serve restic --timeout 10m --addr localhost:0 mega:/backups
root 57132 1 0 Oct30 ? 00:00:05 rclone serve restic --timeout 10m --addr localhost:0 mega:/backups
root 57892 1 0 Oct30 ? 00:00:05 rclone serve restic --timeout 10m --addr localhost:0 mega:/backups
root 58513 1 0 Oct30 ? 00:00:03 rclone serve restic --timeout 10m --addr localhost:0 mega:/backups
root 59245 1 0 Oct30 ? 00:00:03 rclone serve restic --timeout 10m --addr localhost:0 mega:/backups
root 60749 1 0 00:00 ? 00:00:02 rclone serve restic --timeout 10m --addr localhost:0 mega:/backups