cro3 icon indicating copy to clipboard operation
cro3 copied to clipboard

SSH process for port redirection should be terminated properly

Open hikalium opened this issue 9 months ago • 1 comments

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 avatar May 02 '24 07:05 hikalium

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

hikalium avatar Jun 06 '24 07:06 hikalium