When executing tmux inside a tmux session, my expectation would
be that the command would default to accessing that same session.
Here's an example that breaks this assumption:

0. Check that there are no tmux sessions.

  $ tmux list-sessions
  no server running on /tmp/tmux-1000/default

1. Start a session and let it die.

  $ ./tmux set-window-option -g allow-rename off \; \
        new-session -d -s dead-session -n sleep sleep 1 \; \
        set-window-option -t sleep remain-on-exit yes

2. Start the second (interactive) session.

  $ ./tmux new-session -s second-session -n shell

3. Inside the second session create a new window.

  $ ./tmux new-window -n new-window

4. List the windows

  $ ./tmux list-windows -a
  dead-session:0: sleep- (1 panes) [80x47]
  dead-session:1: new-window* (1 panes) [80x47]
  second-session:0: shell* (1 panes) [80x47]

The new-window has been created in the dead-session even while
the command to create it was executed inside the second-session!


As far as I can tell, this happens because the pty names are
used to find the matching session. The dead session releases
its pty allowing it to be re-used, but at the same time keeps
the name in the internal structure. When the second session
then ends up re-using the same pty, it triggers this conflict.

With the quick hack below, the result in step #4 looks like this:

  $ ./tmux list-windows -a
  dead-session:0: sleep* (1 panes) [80x47]
  second-session:0: shell- (1 panes) [80x47]
  second-session:1: new-window* (1 panes) [80x47]

..., which matches what I would expect to happen. Another
alternative would probably be to keep the pty reserved as long
as the dead session still exists, but that seemed to have more
possible side effects and it wasn't immediately obvious to me
if doing it would have any benefits over this way.


The example above isn't really a sensible use-case, but this
phenomenon was actually discovered in real use with a more complex
setup and caused that system to break. While we need to live with
the issue for now (and try to work around it), I would like to see
it fixed for the future, if possible.


--- a/server-fn.c
+++ b/server-fn.c
@@ -308,6 +308,7 @@ server_destroy_pane(struct window_pane *wp, int notify)
                bufferevent_free(wp->event);
                close(wp->fd);
                wp->fd = -1;
+               wp->tty[0] = '\0';
        }
 
        if (options_get_number(w->options, "remain-on-exit")) {

-- 
You received this message because you are subscribed to the Google Groups 
"tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to