Solved ssh connection breaks, when using tmux on top of ssh - any suggestion where to look ?

I use ssh to connect to my server from an actual macOS system. There are two diffrent behaviours when the macOS is awaking from sleep: when I only had a ssh connection to the server it is still connected. When I use a tmux session on top of the ssh connection, I get something like the "client_loop: send disconnect: Broken pipe" . So it seems that the ssh session is a stable connection while tmux send something like "HUP" downstream.
( when I reconnect ssh server and tmux attach ... everything will work fine until the next sleep happens ) . So I wonder if somebody has similar observations ?
Or any tips where I need to change what parameter for tmux ( at least I still believe tmux is the problem ) ?
 
So, you run tmux on the destination host? Not locally? SSH would just time out if your macOS goes to sleep, the connection is dropped and tmux simply disconnects the session. Which you can later pick up again ( tmux at) after you reconnected with SSH. That's the whole point of using tmux in the first place, you can reconnect the session after the connection has been broken (for whatever reason).

You can't keep the connection open if the computer goes in sleep mode, the network card is turned off too, thus no network traffic is possible.
 
Hmm, yes this is the way I use it (tmux on the destination host etc.)
What I wonder, when I only use ssh to connect to the destination host, it keeps the connection even during sleep. When I wake up the macOS (local host) the connection is still there. when I start tmux on the destination and are inside the tmux-session , the connection breaks during sleep. And I have to reconnect with ssh and attach to the tmux session again.

So do you mean tmux will actively send a "disconnect" message to the underlying ssh connection ?

I have added
Code:
    ServerAliveInterval 180
    IPQoS=throughput

to my .ssh/config to keep the ssh session open until I shut down my local host. This works fine for the ssh-only session. As soon as I use tmux on top, the connection will break during a nap.

Oh, I have activated "PowerNap" on my macOS, which keeps the network card somehow running to get new mail, synchronize cal etc. while the rest of the mac is not working ( works only on Intel )
 
Tmux doesn't do anything, it simply runs on the TTY session you have (either through ssh(1) or a local TTY). If that connection is terminated then tmux will simply disconnect from the TTY, not the other way around.

which keeps the network card somehow running to get new mail, synchronize cal etc.
Those are all new connections. It's possible the network card is woken up then the application connects to your mailserver to check and disconnects again. Those are not 'continuous' connections, the connection is made, information is exchanged and the connection is terminated.
 
I close this thread as it is not such a critical error. It seems that tmux is sending a disconnect after some inactivity - otherwise I could not explaoin, while a pure ssh connection stays ( also after the nap) and only with a running tmux session it is disconnecting . Also if tmux server is running, but I am not attached, the ssh connection is staying. so it seems a communication between tmux-server and the pty that leads into a disconnect.
At the end tmux is currently making what I use it for ( long term runs ). So I don't investigate further.
 
Those are all new connections. It's possible the network card is woken up then the application connects to your mailserver to check and disconnects again. Those are not 'continuous' connections, the connection is made, information is exchanged and the connection is terminated.
Yes, but the ssh will send a kind of heartbeep to the connected host to keep the line open and ensure that the remote host sshd is not disconnecting. So at least this would be not a new session.
 
but the ssh will send a kind of heartbeep to the connected host to keep the line open and ensure that the remote host sshd is not disconnecting.
Sure, but that will continue to happen, if you run tmux or not. Tmux does absolutely nothing with the ssh connection, it's not even aware of it, it runs on a tty regardless where that tty came from. You can disconnect tmux from the tty using ctrl-b, d, and that's all it's able to do. This will simply drop you back into the shell session you started with before you launched tmux.
 
I run new ssh agents inside tmux on the target system. Once you have one all the other tmux sessions on the same system can share it.
OK, this is sharing the same tunnel for the ssh connection, nor ? I only open one ssh connection which will then play the tmux-client. So all the communication is anyhow going through this connection. with this i start the tmux-server opening different windows in the same session ( my user, toor, special user replication, tail some logs) This server session will stay ( of course as this is the benefit of tmux ) Only may tmux-client will die and also kills the underlaying ssh
 
Ok, ash on my head - yesterday night I could observe that even without tmux I received "client_loop: send disconnect: Broken pipe" - so it is also happening from time to time with ssh. The only observation with tmux is, that when I make a sudo su - user there is no additional tmux-client and tmux is missing in that window the server socket ( /tmp/tmux-uid/default).
No tunnel involved. I just copy the $SSH_AUTH_SOCK variable from the first tmux which is holding the agent. It is entirely local to the remote machine.
Hmm, I don't get this. I have ONE ssh connection to the server. (There is an ssh-agent running as Damon). I start within the shell tmux new-session. and so I get ONE tmux client and ONE tmux server. both are connected through a local socket on the remote host ( /tmp/tmux-uid/default ) inside the tmux server I open several new-windows with shells or whatever. Why would I use $SSH_AUTH_SOCK ?

What I have installed on the host in general is security/keychain to simplify my life. I only allow ssh with PupkeyAuthentication. To prevent typing the passphrase every time, I use security/keychain. It will capture the passphrase until the next reboot. So I have protected ssh keys, but also an easier life for connection.
 
Sorry to revive this old topic, but I don't understand the solution. I experience the very same problem described in the OP.
I use my Mac as a remote terminal station. I have 2 terminal windows open. Each terminal window opens a ssh session to the same linux host.

On terminal-1: I open ssh connection to host, and work within the login shell.
On terminal-2: I open ssh connection to host, then start a tmux session and work.

If I resume work after the Mac suspends/sleeps:
terminal-1 (ssh-only) session is still active.
terminal-2 (ssh-tmux) session has disconnected requiring reopening ssh connection, and reattaching to tmux.

I don't understand why the different behavior of the 2 ssh sessions. I would prefer both to remain connected.
 
Back
Top