Ubuntu – Byobu creating new session on every connection

byobutmuxUbuntu

Every time I connect to my Ubuntu 17.10 machine with byobu-enable turned on, I get a new "session" rather than it reusing my existing sessions.

On connect:

Byobu sessions...

  1. tmux: foo: 3 windows (created Sun Jan 28 10:23:59 2018) [204x53] (group foo)
  2. tmux: ba: 1 windows (created Sun Jan 28 10:24:16 2018) [204x53]
  3. Create a new Byobu session (tmux)
  4. Run a shell without Byobu (/bin/bash)

Upon selecting one, say (1), I am dumped to a byobu session named e.g. _foo-20462

$ byobu list-session
_foo-20462: 4 windows (created Sun Jan 28 10:42:20 2018) [204x53] (group foo)
foo: 4 windows (created Sun Jan 28 10:23:59 2018) [204x53] (group foo)
bar: 1 windows (created Sun Jan 28 10:24:16 2018) [204x53]

The odd thing is that _foo-20462 appears to be an exact replica of the "foo" session. The only way I can figure out to kill these is byobu kill-session -t _foo-20462, but I figure there must be a way to disable this behavior, as it was not the same in prior versions of Ubuntu.

Best Answer

I had the same problem and found a fix. I created an issue about this:
https://bugs.launchpad.net/byobu/+bug/1750430

I put on my detective hat and managed to fix it.


TL;DR - Either call tmux directly or revert a change in Byobu's select-session.py.


Running a plain tmux command attaches to the first session, so this is probably the easiest "fix" for this (the oddly named sessions are only created with the tmux backend, not with screen).


However, you can fix this for Byobu, too.

man byobu revealed that the part of Byobu that's responsible for selecting the session is byobu-select-session.

which byobu-select-session directed me to /usr/bin/byobu-select-session, which in turn calls /usr/libexec/byobu/include/select-session.py. These paths may be different for you (I'm on Fedora).

The line in select-session.py that creates and names the session is this one (in the function attach_session()):

os.execvp("tmux", ["tmux", "-2", "new-session", "-t", session_name, "-s", "_%s-%i" % (session_name, os.getpid())])

So, Byobu intentionally creates a session named _%s-%i, where %s is the session name and %i is the PID.

Looking into the Git blame for the line shows this commit:
https://github.com/dustinkirkland/byobu/commit/c0050ac51ee8accc3eb35862483bc40b19e3c269

Reverting the line fixes the issue:

os.execvp("tmux", ["tmux", "-2", "attach", "-t", session_name])

...but probably also removes support for "tmux grouped sessions", but I'm not entirely certain what they're used for, and I can live without them.

Related Topic