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?

6
  • 2
    Does this answer your question? How to prevent "Write Failed: broken pipe" on SSH connection?
    – zwets
    Commented Jan 16 at 20:17
  • Hello, two great answers are proposed in that question, one is editing the config file, unfortunately it does nothing to the server's own ability to disconnect after a period of inactivity, even tho it does mitigate the risk. The other answer suggests the screen utility that, while great, it doesn
    – SO_32
    Commented Jan 16 at 20:26
  • 't look like prevention method, more like a recovery one. What is in my own answer does prevent the connection to time out =)
    – SO_32
    Commented Jan 16 at 20:27
  • Let me expand, 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 won't do anything to the fact that my salloc command has been canceled by slurm. I would now have to start another queue =( , so if I understood the point of screen correctly, and the fact that editing the config file gives no guarantees, this option (in my answer) looks quite solid
    – SO_32
    Commented Jan 16 at 20:32
  • I'm not intimately familiar with slurm, but why would it cancel the command if your screen session is still running? It has no way to see you're not there.
    – zwets
    Commented Jan 16 at 20:54

1 Answer 1

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.

2
  • This hack gets my +1 on creativity but also blew my WCGW detector. Have you tested what happens if the Enter key events are sent to your lock screen? Or to the comment box on AskUb
    – zwets
    Commented Jan 16 at 20:26
  • So, for instance, for i3lock it would keep sending empty passwords I believe, I can test it on a virtual machine if you wish, but I have no reason to believe that the lock screen would be exempt. I do remark regardless of what you are doing, given that unwanted Return commands can cause trouble if, for instance, you forget that this measure is in place. I see why it blew your WCGW detector =)
    – SO_32
    Commented Jan 16 at 20:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .