Please don't kill SSH when detaching on Ctrl+C signal.
SSH have a powerful feature to reuse existing connections. For example if ~/.ssh/config have the following:
host * controlmaster auto controlpath ~/.ssh/__tmp-ssh-%r@%h:%p
then SSH will create a socket file for first connection to remote host and subsequent connections will reuse the existing connection through the sock file.
When you log off from first "master" session, SSH will not exit until all other connections are closed. If you terminate "master" SSH process then all other connections to the same host will be terminated as well.
In Xpra when I attach to remote session without any prior ssh connections to the remote host a "master" connection is created. If later I have other SSH connections to the same host they are reusing "master" SSH connection initiated by Xpra.
The problem is that all SSH connections are terminated if I detach from "master" session by sending "Control-C" to Xpra client because it kills master SSH connection. This do not happen when I detach using "Disconnect" from Xpra client menu.
ssh may currently receive the Ctrl+C, we would have to prevent that - and doing that would mean that we may make it more difficult to interact with ssh via the terminal (password input for example).
then we have to hook up the signal handler to fire the disconnect code.
do-able but tricky.
please try r2029 and let me know if that works for you
This is more complicated than it seems, and here are some useful pointers I found along the way:
Well done, this fixes the issue. Thank you.
Xpra-0.8.8 is exhibit this problem again...
When two or more sessions are attached to the host, terminating first Xpra session with Ctrl+C terminates the other one(s) as well because it closes SSH control connection.
This was caused by r2762, see #260
This probably fixes it:
--- src/xpra/scripts/main.py (revision 2907) +++ src/xpra/scripts/main.py (working copy) @@ -556,6 +556,17 @@ ssh_fail_cb(error_message) raise IOError(error_message) def stop_tunnel(): + if os.name=="posix": + #on posix, the tunnel may be shared with other processes + #so don't kill it... which may leave it behind after use. + #but at least make sure we close all the pipes: + for name,fd in {"stdin" : child.stdin, "stdout" : child.stdout, "stderr" : child.stderr}.items(): + try: + if fd: + fd.close() + except Exception, e: + print("error closing ssh tunnel %s: %s" % (name, e)) + return try: if child.poll() is None: #only supported on win32 since Python 2.7
Since terminating the ssh process may or may not be the right thing to do, depending on what platform you are on, how ssh is setup, personal preference, etc.. maybe this should even be an option?
applied in r2908, will backport to 0.8.x
closing, feel free to re-open if not fixed
Unfortunately, this has caused a bad regression: this prevents us from using password mode with ssh, see #380
So unless a better solution can be found, I will remove this code.
Since it is impossible to have both, r5862 deals with this problem by giving the user the option of having keyboard interaction (--exit-ssh
- which is now the default) or having connection sharing (--no-exit-ssh
).
Information added here: wiki/SSH.
this ticket has been moved to: https://github.com/Xpra-org/xpra/issues/203