ssh -X user@machine hangs when using exit to terminate

Bug #592434 reported by Bonnie
100
This bug affects 21 people
Affects Status Importance Assigned to Milestone
D-Bus
Unknown
Wishlist
dbus (Debian)
New
Unknown
dbus (Ubuntu)
Fix Released
Low
Unassigned
Nominated for Lucid by Chandresh Prakash

Bug Description

ssh -X user@server hangs when using exit to terminate

Steps to reproduce:
user@client:~$ ssh -X user@server
user@server:~$ gedit

At this point gedit from server will run locally. Closing the program and returning to the terminal you run:

user@server:~$ exit
logout

At this point the terminal hangs on the echo logout, but does not return to the client prompt. The action has been consistent when connecting to a server running opensolaris or ubuntu 8.04.
The client is using Ubuntu 10.04 and the server is using 8.04, and using default password authentication. As you will see in the video attached I can confirm the issue when using a clean Ubuntu 10.04 as a client and Ubuntu 8.04 as the server, using default password authentication.

Workaround
----------
-When logging out with "exit" and it hangs, press Ctrl-C
-If you would like to simply use gedit on another computer use the following command:
  $ dbus-launch gedit

Date: Thu Jun 10 17:34:26 2010

Revision history for this message
Bonnie (lucas-usna) wrote :
komputes (komputes)
description: updated
Changed in openssh (Ubuntu):
status: New → Confirmed
Revision history for this message
komputes (komputes) wrote :
Changed in openssh (Ubuntu):
importance: Undecided → Low
status: Confirmed → Triaged
Revision history for this message
Chandresh Prakash (kcn-viper) wrote :

Although probably not important but it is irritating. I ran ssh in verbose mode found the following difference between normal exit and 'ssh -X' exit when reproducing:

Exit from 'ssh -vX' after running gvim and closing it:
logout
debug1: channel 0: free: client-session, nchannels 3

Exit from 'ssh -v':
logout
debug1: channel 0: free: client-session, nchannels 1
Connection to funny.local closed.
Transferred: sent 3552, received 3448 bytes, in 1.8 seconds
Bytes per second: sent 1968.9, received 1911.2
debug1: Exit status 0

Revision history for this message
Maciej Puzio (maciej-puzio) wrote :

I am also experiencing this problem on Ubuntu 10.04, openssh-server 1:5.3p1-3ubuntu4, as well as on Ubuntu 9.10. I would like to clarify that the problem appears to lie within the server, not the client. My client is running CentOS 5.5 and the problem occurs when connecting to Ubuntu servers, but not when talking to servers running CentOS 5.5. However, I have noticed the same problem with a Fedora server, so it may be an upstream bug.

Revision history for this message
Alex Waite (alexqw85) wrote :

There is a form thread [1] that discusses this problem and has some more verbose output and analysis on this. Thoughts anyone?

[1] http://ubuntuforums.org/showthread.php?t=1481344

Revision history for this message
Alex Waite (alexqw85) wrote :

This is a guess, but could the entry for 20100816 be a fix for this?
ftp://ftp.ca.openbsd.org/pub/OpenBSD/OpenSSH/portable/ChangeLog

Revision history for this message
In , Colin Walters (walters) wrote :
Revision history for this message
In , Colin Walters (walters) wrote :

Created attachment 41260
systemd install: Use -f for "ln"

We do want to overwrite an existing install; use case is "jhbuild"
type setup.

Revision history for this message
In , Colin Walters (walters) wrote :

Created attachment 41261
dbus-launch: Refactor duplicate code

De-duplicate execl() invocations of dbus-daemon.

Revision history for this message
In , Colin Walters (walters) wrote :

Created attachment 41262
Scope autolaunch to requesting client, don't connect to X server

Previously, when logging in via ssh with X forwarding, since
on most operating systems there is no DBUS_SESSION_BUS_ADDRESS,
we autolaunch a bus. In this is that dbus-launch will
connect to the remote X server and scope itself to that, which
will cause ssh to refuse to exit because there are still clients.

Basically:
ssh -X remotehost
firefox &
<Control-d>

Now, scoping of the bus is a long debated mess, but there is
a reasonable fix for the ssh -X case; we scope the bus lifetime
to the requesting client, not to the X server.

This patch adds --exit-after-clients-exit option to the bus, which
will cause the bus, after an initial connection is made once, to exit
after it has no connections.

dbus-launch --autolaunch is modified to use this. Now, in the
Firefox case what's actually going on is that it talks to GConf,
which was recently modified to scope to DBus, bus since no bus
is available it autolaunches one. The resulting gconfd-2 process
hangs around after ssh exits, but will eventually time out.

Possible regressions:
* Previously dbus-launch looked at the X server to try to find
  a bus address; this worked in the "local" (i.e. same uid-kernel)
  case where one manually sets:
  DISPLAY=:0 somedbusapp
  A specific example of this case is the legacy Unix getty. But
  I don't see this as a big problem; there are other environment
  variables, and really, the right fix for this is to have the
  OS default to single session.

Revision history for this message
In , Colin Walters (walters) wrote :

Created attachment 41273
updated patch

V2: Clean up dbus-launch.c even more to be sure we don't connect to X in autolaunch case.

Revision history for this message
In , Thiago Macieira (thiago-kde) wrote :

DISPLAY=:0 some-dbus-command

is very much used. You cannot remove this functionality.

Revision history for this message
In , Colin Walters (walters) wrote :

(In reply to comment #5)
> DISPLAY=:0 some-dbus-command
>
> is very much used. You cannot remove this functionality.

Well, eventually my goal is just

"some-dbus-command" works (this gets back to OS single session).

I agree maintaining DISPLAY= setting for legacy gettys is desirable (I use it myself sometimes), though I don't see such a hard and fast "you cannot remove" rule for random Linux voodoo commands.

The question is - can we come up with a variation that "fixes" the ssh case without changing anything else?

It looks like recent versions of OpenSSH put "SSH_CONNECTION" in the environment; in that case, we could simply not connect to X. We could also check inside dbus-launch for whether the X is remote, and if so ignore it.

However - if it comes down to "do we 'break' getty or do we 'unbreak' ssh", I think the latter really has to win.

Revision history for this message
In , Thiago Macieira (thiago-kde) wrote :

What's wrong with ssh?

Yes, I have run programs with remote X sessions and they start D-Bus.

The only thing missing in the autolaunch implementation is "suicide mode" -- the server exit by itself when the last application disconnects. DCOP had this feature, but I don't see how useful this will be today unless applications also disconnect after a while. In KDE 4, they don't.

Revision history for this message
In , Colin Walters (walters) wrote :

(In reply to comment #7)
> What's wrong with ssh?

Read the linked Red Hat bug in comment #1 .

> Yes, I have run programs with remote X sessions and they start D-Bus.
>
> The only thing missing in the autolaunch implementation is "suicide mode" --
> the server exit by itself when the last application disconnects. DCOP had this
> feature, but I don't see how useful this will be today unless applications also
> disconnect after a while. In KDE 4, they don't.

If "a while" was "basically immediately", that might help this case; would require a gconf patch.

But I am looking for relatively noninvasive fixes at the moment, until we finally land singleton sessions.

Revision history for this message
In , Thiago Macieira (thiago-kde) wrote :

(In reply to comment #8)
> (In reply to comment #7)
> > What's wrong with ssh?
>
> Read the linked Red Hat bug in comment #1 .

Ok, so the daemon should exit after the apps exited.

> If "a while" was "basically immediately", that might help this case; would
> require a gconf patch.
>
> But I am looking for relatively noninvasive fixes at the moment, until we
> finally land singleton sessions.

Singleton sessions won't solve the problem either because the current style of session busses will still exist. Adding a new functionality doesn't solve issues with existing functionality.

I think that the "suicide mode" is probably the best option: when the last application disconnects, the bus waits for a timeout and disconnects on its own. The timeout doesn't have to be long -- 5 seconds is probably long enough.

When the daemon exits, the X11 window is closed too.

Revision history for this message
In , Colin Walters (walters) wrote :

(In reply to comment #9)
>
> Ok, so the daemon should exit after the apps exited.

That's the first part of my patch, yes.

But that still doesn't fix this case, because gconfd-2 will hang around; in general, any bus activated services.

> > If "a while" was "basically immediately", that might help this case; would
> > require a gconf patch.
> >
> > But I am looking for relatively noninvasive fixes at the moment, until we
> > finally land singleton sessions.
>
> Singleton sessions won't solve the problem either because the current style of
> session busses will still exist.

In older operating system releases, yes.

> Adding a new functionality doesn't solve
> issues with existing functionality.

It would fix later operating systems.

> When the daemon exits, the X11 window is closed too.

Except as above, that's not good enough for this case.

My strong intuition is to simply axe off autolaunching entirely in the ssh case somehow. It's really not desirable, since you can easily get e.g. multiple gconfd-2 processes stomping on each other.

Revision history for this message
In , Thiago Macieira (thiago-kde) wrote :

(In reply to comment #10)
> (In reply to comment #9)
> >
> > Ok, so the daemon should exit after the apps exited.
>
> That's the first part of my patch, yes.
>
> But that still doesn't fix this case, because gconfd-2 will hang around; in
> general, any bus activated services.

That's a problem of those applications, not a D-Bus problem.

However, one thing we can do to help out is to introduce a "daemon connection" mode. The connections left in daemon mode are not counted towards "quit after last application exits". That way, these daemons quit after D-Bus itself quits, which is after the last non-daemon connection quits.

> > Singleton sessions won't solve the problem either because the current style of
> > session busses will still exist.
>
> In older operating system releases, yes.

We agreed not to remove the session bus. It will still exist in the model that it exists today.

> > Adding a new functionality doesn't solve
> > issues with existing functionality.
>
> It would fix later operating systems.

It wouldn't because the current mode of sessions will still exist and be in use. Therefore, it's not a solution for the current mode of operation.

> > When the daemon exits, the X11 window is closed too.
>
> Except as above, that's not good enough for this case.
>
> My strong intuition is to simply axe off autolaunching entirely in the ssh case
> somehow. It's really not desirable, since you can easily get e.g. multiple
> gconfd-2 processes stomping on each other.

But that would simply negate the use-case of why autolaunching was introduced, without replacing it with something else that solves the same problem.

The problem is to start applications that depend on D-Bus without D-Bus having been started. It was introduced mostly for the legacy case of desktop environments that didn't start D-Bus on their own (which was the rule back in 2006), but it's also true for X11-forwarded SSH sessions.

Revision history for this message
In , Colin Walters (walters) wrote :

Havoc, any opinion here?

Revision history for this message
In , Hp-pobox (hp-pobox) wrote :

Historically, autolaunch was an important feature for KDE and we agreed to include it due to that, so I don't think we should break it if it's avoidable.

Having the bus exit when there are no connections, and allowing "daemon" connections that don't block exit, seem like useful features orthogonal to any big picture debate and even to whether autolaunch is enabled. If nothing else this would make a manual invocation work nicely:
 dbus-launch myapp
(which is what I usually do when using sudo I suppose)

Broader comment -

I feel like there's an unresolved big picture in this general area; the questions on the "what should happen with su/ssh" bug (too lazy to look up number) are still unresolved, and the "switch to one session per user per machine at a time" thread also just kind of ended without an agreed plan. I mean, nobody has ever fully spelled out a full, final answer on how all this should all work... and of course it's not coded either. It's endless piecemeal bugs until there's a document that covers *all* the things people think should work, proposing which will work, which get punted, and exactly how it all works... including potentially ugly pain like OS or openssh patches...

I'm thinking a document that tries to get all combinations of NFS homedir vs. not, su, "su -", sudo, ssh, X vs. console, multiple logins on one machine, interoperation with old Linux or Solaris, etc. - saying which work, which don't, and how they work so when they don't we can point to the root cause. And close stuff By Design while pointing to an actual design doc.

That said -

=> Please, never block on my opinion, though as you know I'm happy to add .02 to anything. :-P

Revision history for this message
Joe Joysn (joysn71) wrote :

issue still available in 12.04 LTS

Revision history for this message
Joe Joysn (joysn71) wrote :

debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype <email address hidden> reply 0
debug2: channel 0: rcvd eow
debug2: channel 0: close_read
debug2: channel 0: input open -> closed
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug2: channel 0: obuf empty
debug2: channel 0: close_write
debug2: channel 0: output drain -> closed
debug2: channel 0: rcvd close
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 3

^Cdebug1: channel 3: free: x11, nchannels 2
debug1: channel 4: free: x11, nchannels 1
debug1: Killed by signal 2.

Revision history for this message
Maciej Puzio (maciej-puzio) wrote :

I can confirm the issue still occurring in 12.04.
openssh-client and openssh-server version 1:5.9p1-5ubuntu1

Revision history for this message
monochromec (monochromec) wrote :

This bug is still around 12.10. Openssh client and server version 1:6.0p1-3ubuntu1.

Given the duration and progress (or lack thereof :-) of this bug: Anybody looking at this upstream?

Revision history for this message
monochromec (monochromec) wrote :

PS: I got the the following when I ran the ssh client with -vvvX and started an X11 application:

debug3: channel 0: will not send data after close
debug2: channel 0: obuf empty
debug2: channel 0: close_write
debug2: channel 0: output drain -> closed
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 3
debug3: channel 0: status: The following connections are open:
  #0 client-session (t4 r0 i3/0 o3/0 fd -1/-1 cc -1)
  #2 x11 (t4 r4 i0/0 o0/0 fd 8/8 cc -1)
  #3 x11 (t4 r5 i0/0 o0/0 fd 9/9 cc -1)

In contrast to this, ssh with just -vvv produced the following output when logging out of the server:

debug3: channel 0: will not send data after close
debug2: channel 0: obuf empty
debug2: channel 0: close_write
debug2: channel 0: output drain -> closed
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
  #0 client-session (t4 r0 i3/0 o3/0 fd -1/-1 cc -1)

Revision history for this message
monochromec (monochromec) wrote :

Only happens with server versions later than 6. Server version 5.1p1-40.15 checks out OK... (albeit with the server running on OpenSuSE 10.3).

Revision history for this message
Bryan Quigley (bryanquigley) wrote :

This is really a dbus issue, not a SSH issue:
see http://serverfault.com/questions/405518/how-to-configure-d-bus-and-ssh-x-forwarding-to-prevent-ssh-from-hanging-on-exit

Gedit for whatever reason is looking for an active dbus-session and running `dbus-launch --autostart' if none was found. But `dbus-launch --autostart' doesn't watch the user session and therefore ssh hangs while waiting dbus-launch to quit.

A workaround is to run 'dbus-launch --exit-with-session' when you first connect over SSH. (This unfortunately causes yet another issue: https://bugs.launchpad.net/ubuntu/+source/dbus/+bug/812913)

affects: openssh (Ubuntu) → dbus (Ubuntu)
Changed in dbus:
importance: Unknown → Medium
status: Unknown → Confirmed
Revision history for this message
Ritesh Khadgaray (khadgaray) wrote :
description: updated
description: updated
Revision history for this message
Wimmer (wimmer184) wrote :

still there on 14.04.
Is anybody looking into that?
I understand its not a huge bug, but it is pretty annoying.

Revision history for this message
Bryan Quigley (bryanquigley) wrote :

I've given up on it for now.. it requires substancial changes and is a quasi-design flaw with dbus.

I am curious (- I haven't checked) what happens with the switch to sdbus/kdbus.

Eventually it might be worthwhile to actually have dbus start and manage your ssh session (the server side only of course) and then everything should might work fine, then you can have bash as a systemd managed user job.

Changed in dbus (Debian):
status: Unknown → New
Revision history for this message
Bryan Quigley (bryanquigley) wrote :

This has been fixed in Ubuntu 16.10. I'm guessing by systemd/dbus changes but I'm not sure. Tested with gedit and virt-manager.

Changed in dbus (Ubuntu):
status: Triaged → Fix Released
Revision history for this message
In , Gquigs+bugs (gquigs+bugs) wrote :

This is fixed Ubuntu 16.10, haven't investigated where the fix came from.

Revision history for this message
Anthony Jenkins (scoobi-doo) wrote :

Try running the remote X client using dbus-run-session(1), which I have on my FreeBSD build of dbus:

$ ssh mybox
$ dbus-run-session -- gedit

I came across this thread looking for why ssh sessions in which I ran /certain/ X clients would hang the session when I tried to exit. Now that I know it's a dbus issue, I came across a dbus session wrapper program that suits my needs perfectly. Now I can alias those naughty commands while in an ssh session.

Revision history for this message
In , Gitlab-migration (gitlab-migration) wrote :

-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/dbus/dbus/issues/34.

Changed in dbus:
importance: Medium → Wishlist
status: Confirmed → Unknown
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.