Logging into my Linux server which hosts many Docker containers, I saw a warning that "There are 320 zombie processes." That seems bad! You can see which processes are involved using:
ps axo stat,ppid,pid,comm | grep -w defunct
They are all mongosh
and that only comes from one of the docker containers running the MongoDB server. What is wrong here? And are these a problem?
The zombie processes exist because they were killed and some other process is still waiting for info from them. Not a big deal but probably unwanted.
My server is running via Docker Compose. In the compose file I had a health check which is using mongosh
to ping MongoDB internally. The timing of that was too short and it was being killed:
healthcheck:
test: "mongosh ... --eval 'quit(db.runCommand({ ping: 1 }).ok ? 0 : 1)' || exit 1"
interval: 30s
retries: 5
start_period: 1s # <-- That start_period is the problem
timeout: 10s
Setting the start_period
to 10s
and restarting the container fixed everything. Zombie apocalypse averted!