google / cro3

Abstraction Layer of ChromiumOS development
https://google.github.io/cro3/
BSD 3-Clause "New" or "Revised" License
36 stars 12 forks source link

SSH process for port redirection should be terminated properly #244

Open hikalium opened 5 months ago

hikalium commented 5 months ago

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
hikalium commented 3 months ago

It is implemented in abtest branch so let me extract it to a new branch for review...