0

How do I prevent the Broken Pipe error from the client side of the ssh connection on ubuntu?

Let's say that slurm is running on the server and I just made a salloc request. If the connection is broken, recovering the session (with, say screen) won't do anything to the fact that my salloc command has been canceled by slurm. I would now have to start another queue. Is there a way to prevent a broken pipe on the client side, given that editing the .ssh/config file, while mitigating the risk, gives no guarantees?

SO_32
  • 181

1 Answers1

0

Aside from the well known Client side solution, that unfortunately doesn't prevent the Server from closing the connection after a certain period of inactivity, that is including something on the lines of

ServerAliveInterval 30
ServerAliveCountMax 240000000

in the

/home/username/.ssh/config

file and restarting sudo systemctl restart ssh, I've found that the following works wonderfully. By using xdotool

sudo apt update
sudo apt install xdotool

one can write a no_more_broken_pipes.sh file that contains something on the lines of

NBP() {
while true
do
        sleep 10
        xdotool key Return
done
}

When ran, that is

source no_more_broken_pipes.sh
NBP

it will press Return every ten seconds, regardless of what you are doing, until you abort it with ctrl+c.

As long as you are focused on the right terminal, the server will receive inputs every ten seconds (sleep 10), so the connection won't be terminated, even if you go on vacation. If using the return key is not a good idea, the xev tool will help determine what to write on the command so that a safer key is pressed.

Cautionary tale

While doing this, you should also prevent any pop-up window (of any kind) to appear. I'm including log-in screens (such as i3lock), available update messages, whatnots. What works incredibly well for me, as long as just one terminal is involved, is the full screen of i3 (usually Super_L+f): it automatically prevents (so far it has been this way for me) the focus on new windows.

SO_32
  • 181