Don't crash if status of PID from runtime directory cannot be determined
In !4700 (merged), Gitaly will crash if it cannot send the signal 0 to a PID, derived from a directory in the runtime dir:
time="2022-07-15T15:18:54.991Z" level=error msg="runtime directory contains an unexpected file" path=/Users/stanhu/gdk-ee/gitlab/tmp/run/.gitkeep
time="2022-07-15T15:18:54.991Z" level=error msg="shutting down" error="prune runtime directories: signal: operation not permitted"
This happened to a number of GDK users since this update.
I think we can improve this in a few ways:
- Verify the executable name of the PID is actually
gitaly
(e.g. via https://github.com/mitchellh/go-ps). - Check if it's still running. If it is, keep the runtime directory.
- If the permission is denied, skip the runtime directory and log a message.
- If it's not running, or it's another binary name, remove the runtime directory.
Edited by Stan Hu