cro3
cro3 copied to clipboard
SSH process for port redirection should be terminated properly
sometimes the child processes (for ssh port forwarding) do not terminate properly and keep listening to the port to be forwarded, which can use up all the available ports eventually. We should investigate why it happens and fix that for most of the cases.
For now, you can run this script in the background to kill the stale processes periodically:
function clean_defunct_ssh_processes() {
cat /proc/1/task/*/children | sed 's/ /\n/g' | xargs -I {} -- grep -a --with-filename '^ssh$' /proc/{}/comm /proc/{}/cmdline | cut -d '/' -f 3 | xargs -I {} -- bash -c "echo {}; kill {}"
}
for ((i = 1; 1; i++)); do
clean_defunct_ssh_processes
echo "Done. Next run will be in 5 min..."
sleep 300
done
It is implemented in abtest branch so let me extract it to a new branch for review...