Bug 1917 - Escape sequence (~) doesn't work right with ControlMaster/ControlPersist connections
Summary: Escape sequence (~) doesn't work right with ControlMaster/ControlPersist conn...
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: ssh (show other bugs)
Version: 5.8p1
Hardware: All All
: P2 normal
Assignee: Assigned to nobody
URL:
Keywords:
: 1938 (view as bug list)
Depends on:
Blocks: V_6_3
  Show dependency treegraph
 
Reported: 2011-07-05 07:11 AEST by Jeremy Nickurak
Modified: 2015-08-11 23:04 AEST (History)
4 users (show)

See Also:


Attachments
allow ~. to abandon mux master channels (2.82 KB, patch)
2013-06-07 02:41 AEST, Darren Tucker
no flags Details | Diff
allow ~. to abandon mux master channels, diff vs 6.2p2 (2.85 KB, patch)
2013-06-07 02:50 AEST, Darren Tucker
djm: ok+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jeremy Nickurak 2011-07-05 07:11:43 AEST
When in a non-master ssh session connected to a Master session, ~. is not captured, and therefore the connection cannot be terminated, and the process cannot be easily closed. When a normal Master ssh process is present, escapes can be used on it. This is doubly frustrating with ControlPersist, where the Master connection is always in the background and never directly accessible.

Open question: Should ~. terminate the master connection? Or should it simply terminate the ssh client
Comment 1 Damien Miller 2011-07-06 05:41:18 AEST
I can't replicate this - ~? and ~. work fine for slave connections of a master running in ControlPersist mode. Are you sure you are running 5.8p1 on the client?
Comment 2 Jeremy Nickurak 2011-07-06 05:55:25 AEST
nickuj@nickuj:~$ ssh -V
OpenSSH_5.8p1 Debian-1ubuntu3, OpenSSL 0.9.8o 01 Jun 2010

It's the weirdest thing, I can't duplicate it any more either. I'll keep an eye out to see if I can figure out what changed.
Comment 3 Jeremy Nickurak 2011-07-06 05:59:29 AEST
Just hit again. Seems like if the network goes out, the master connection stalls, and the slave connection can't do escapes anymore.
Comment 4 Damien Miller 2011-07-06 06:26:43 AEST
Is there any chance you could catch the master where it is stalling with strace/ktrace/truss/gdb?
Comment 5 Damien Miller 2011-09-22 21:57:53 AEST
*** Bug 1938 has been marked as a duplicate of this bug. ***
Comment 6 Alex Efros 2011-09-22 22:07:00 AEST
I'm not a C developer, but if you provide me (link to) instructions how to run strace/ktrace/truss/gdb to get info for you - I'll do it when faced with this problem next time.
Comment 7 Damien Miller 2011-09-24 14:00:18 AEST
gdb:

1. find the pid of the unresponsive ssh process using "ps auxww | grep ssh"

2. attach to it using gdb "gdb /path/to/ssh" then "attach PID" (using the pid you found in step (1).

3. Capture a backtrace "where". 

The others depend on which platform you are on. Generally it is a matter of running "strace -p PID" (or similar for the others). ktrace is a little different, because you need to start the trace (using ktrace) then dump the output using kdump later. Check the manpage for the tool for your system.
Comment 8 Damien Miller 2011-10-21 11:16:47 AEDT
I got a chance to catch a ssh client in this state the other day and connect to it with a debugger for a couple of minutes before ServerAliveInterval killed it.

It turns out that the first ~. is actually killing the session, but for some reason the session isn't being released.

Notes for next time:

1) clear server_alive_count_max to get a longer debugging session
2) try attaching before issuing ~.
3) reset log channel to syslog and loglevel to debug3
Comment 9 Jeremy Nickurak 2011-11-11 09:15:51 AEDT
I've been hitting this pretty frequently lately, sshing into a machine with ControlPersist turned on (so the master connection is in a forked-off background process), and then rebooting it. As soon as the connection's gone, the session is frozen and ~. won't help, you have to kill the master process manually.
Comment 10 Darren Tucker 2013-06-07 02:41:54 AEST
Created attachment 2297 [details]
allow ~. to abandon mux master channels

I think I figured this out.

When your network changes or goes away and you disconnection with ~.
ssh sends a channel close.  normally this isn't a problem because the
ssh goes away immediately thereafter.  when you do it in a mux client,
the mux client goes away but the mux master stays up.  normally that's
not a problem either, because the mux master is similarly wedged and
can be ~.'ed too.  that is, unless you also use controlpersist.

when all of these things happen together the ssh mux master, which is
backgrounded, hangs around waiting for the channel close confirmation
from the server, which isn't going to happen because, hey, the network is
busted.  that wouldn't be a problem either except that the backgrounded
mux master won't exit until all its channels are closed, and until it
exits the controlmaster socket remains there preventing you from making
a new one.  the net result is that you can't make any new connections
until you find and kill the backgrounded mux master.

you can't just free the channel on ~. because in the case where the
network is not broken you'll get a channel close from the server for a
non-existant channel and the mux master will fatal.

what this patch does is add a new "ABANDONED" state, which is basically the same as CLOSED or INPUT_DRAINING except it's not counted as an active channel. the ~. sequence then sends a close on the channel and puts it into this state.  if the server confirmation comes back the channel is freed as per normal, but if not it's just kept around but not used.

Please try the attached patch (it's against -current, I'll make an equivalent one against 6.2p2).
Comment 11 Darren Tucker 2013-06-07 02:50:31 AEST
Created attachment 2298 [details]
allow ~. to abandon mux master channels, diff vs 6.2p2
Comment 12 Darren Tucker 2013-06-07 03:15:15 AEST
BTW, steps to reproduce:
1) start the master with controlpersist and wait for it to log in.
2) start the slave.
3) disconnect your network.
4) in one session. type some keystrokes then quit it with ~.
5) do the same in the other
6) profit!

I put a lot of wear and tear on my laptop's ethernet port working on this...
Comment 13 Darren Tucker 2013-06-08 01:39:56 AEST
Thanks.  Patch applied, it will be in 6.3.
Comment 14 Damien Miller 2015-08-11 23:04:27 AEST
Set all RESOLVED bugs to CLOSED with release of OpenSSH 7.1