SSH process for port redirection should be terminated properly
- Dominant language
- Rust
- Stars
- 50
- Forks
- 18
- PR merge metrics
- No merged PRs in 30d
Description
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
```
Contributor guide
Assessment
This issue has not been assessed yet.