The first [issue about zombie processes](https://github.com/go-gitea/gitea/issues/3242) created by Gitea was reported in 2017 and [resurfaced](https://github.com/go-gitea/gitea/issues/13987) on a [regular basis](https://github.com/go-gitea/gitea/issues/19077). Although it does not look pretty, zombie processes are leftovers that do not consume resources and never caused any kind of harm. Here is one scenario that will create a zombie:
* Gitea updates a mirror by spawning the process `git remote update`
*`git remote update` spawns yet another process, `git fetch`
*`git fetch` is stuck, for instance because of network problems, and Gitea eventually times out
* Gitea kill the process `git remote update`
* When killed `git remote update` does not kill its own child and `git fetch` becomes an orphaned process which keeps running
* When `git fetch` eventually completes it becomes a zombie because its original parent is no longer around to wait on it
### PID 1 process and waiting on orphans
This scenario is not unique to Gitea and it is such a common pattern that safeguards have been implemented to mitigate the proliferation of zombies. Orphaned process are automatically attached to the process with PID 1, which is expected to wait on every process, whether it created them or not. When Gitea is installed from binary on GNU/Linux this is `/bin/init` and when Gitea runs from the [default docker image](https://github.com/go-gitea/gitea/blob/6171ea7d318c0ca8714bc6efd6a97ea4b495eb6d/Dockerfile) this is `s6`: they will both wait on orphaned processes and there won't be any zombies.
### What if Gitea is the only running process?
But when Gitea runs from the [rootless docker image](https://github.com/go-gitea/gitea/blob/6171ea7d318c0ca8714bc6efd6a97ea4b495eb6d/Dockerfile.rootless), Gitea is the only process running in the container. Orphaned processes will have Gitea as a parent but will not wait on them and they will stay in a zombie state forever. To reproduce this problem in a minimal way:
0 1 gitea /usr/local/bin/gitea -c /etc/gitea/app.ini web
1 94 sleep [sleep]
1 99 sleep [sleep]
1 111 sleep [sleep]
1 165 sleep sleep infinity
```
Killing it will turn it into a zombie:
```
$ docker exec gitea kill 165
$ docker exec gitea ps -o ppid,pid,comm,args
PPID PID COMMAND COMMAND
0 1 gitea /usr/local/bin/gitea -c /etc/gitea/app.ini web
1 94 sleep [sleep]
1 99 sleep [sleep]
1 111 sleep [sleep]
1 165 sleep [sleep]
```
### Killing a child process and all its children
There should be no need for an admin running Gitea to worry about those gory details, it should be taken care of regardless of the environment Gitea runs in. Fortunately there is a very simple way to avoid the creation of zombies by ensuring that all Gitea child process are [process group leaders](https://en.wikipedia.org/wiki/Process_group). In a nutshell it means that when the child is killed all its children and grand children are also killed.