xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.

Opened 10 years ago

Closed 8 years ago

Last modified 17 months ago

#203 closed defect (fixed)

SSH is killed on Control-C detaching

Reported by: onlyjob Owned by: Antoine Martin
Priority: minor Milestone: 0.8
Component: core Version: trunk
Keywords: Cc:


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.

Change History (11)

comment:1 Changed 10 years ago by Antoine Martin

Status: newaccepted

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.

comment:2 Changed 10 years ago by Antoine Martin

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:

Last edited 10 years ago by Antoine Martin (previous) (diff)

comment:3 Changed 10 years ago by onlyjob

Well done, this fixes the issue. Thank you.

comment:4 Changed 10 years ago by Antoine Martin

Resolution: fixed
Status: acceptedclosed

comment:5 Changed 9 years ago by onlyjob

Resolution: fixed
Status: closedreopened

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.

Last edited 9 years ago by onlyjob (previous) (diff)

comment:6 Changed 9 years ago by Antoine Martin

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 @@
                 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
                 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?

Last edited 9 years ago by Antoine Martin (previous) (diff)

comment:7 Changed 9 years ago by Antoine Martin

Resolution: fixed
Status: reopenedclosed

applied in r2908, will backport to 0.8.x

closing, feel free to re-open if not fixed

comment:8 Changed 9 years ago by Antoine Martin

Resolution: fixed
Status: closedreopened

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.

comment:9 Changed 8 years ago by Antoine Martin

Resolution: fixed
Status: reopenedclosed

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).

comment:10 Changed 4 years ago by Antoine Martin

Information added here: wiki/SSH.

comment:11 Changed 17 months ago by migration script

this ticket has been moved to: https://github.com/Xpra-org/xpra/issues/203

Note: See TracTickets for help on using tickets.