How can I keep gnu screen from becoming unresponsive after losing my SSH connection?

2.1k Views Asked by At

I use a VPN tunnel to connect to my work network and then SSH to connect to my work PC running cygwin. Once logged in I can attach to a screen session and everything works great.

Now, after a while, I walk away from my computer and sooner or later, the VPN tunnel times out. The SSH connection on each end eventually times out and then I eventually come back to my computer to do some work. Theoretically, this should be a simple matter of just restarting the VPN, reconnecting via SSH, and then running "screen -r -d".

However apparently when the sshd daemon times out on the cygwin PC, it leaves the screen session in some kind of hung state. I can reproduce a similar hung state by clicking the close box on a cygwin bash shell window while it's running a screen session.

Is there any way to get the screen session to recover once this has happened, so that I don't lose anything?

2

There are 2 best solutions below

0
On BEST ANSWER

With a great deal of experimentation, I was able to recover the screen session as follows:

  1. Lookup the PID of the server screen process: ps | grep screen
  2. Send the server a HUP signal: kill -1 <PID>
  3. Run a screen client: screen -r -d
3
On

screen is blocking on the (dead) SSH session's pty. Recover by killing that sshd.

Assuming Linux, and that you're not currently inside screen:

$ pgrep -U $UID sshd | xargs -rn1 pstree -hp
sshd(16305)───bash(16306)───screen(16670)
sshd(16544)───bash(16545)───xargs(16705)───pstree(16707)
$ kill 16305
$ screen -r