tmux-plugins / tmux-resurrect

Persists tmux environment across system restarts.
MIT License
11.41k stars 424 forks source link

When restoring, some panes of a session are corrupted (placements lost, extra panes appear, commands not restored) #437

Open ioogithub opened 2 years ago

ioogithub commented 2 years ago

I have been tracking several bugs over the course of the past month. I have saved and restored different environments over 100 times. There are several major bugs that I cannot find a way around. Some of the bugs happen every time. Some happen intermittently which suggests timing issue.

Several of the bugs may be related to adding new panes to window in that it messes up the existing panes, placements and histories. Sometimes adding a new pane to one window creates a new pane in a different window. Sometimes the panes are restored with a the placements messed up (almost always bunched together at the top).

Here is what I have found so far:

  1. tmux-resurrect is creating phantom panes in the same window

    • Create a new window with 3 vertical panes
    • Save environment, kill server and restore
    • 4 panes are restored to this window (an extra pane at the bottom)
    • Sometimes it has the history of the 3rd pane and sometimes the history is empty.
    • This is intermittent it happens around 20% of the time.
  2. tmux-resurrect is creating phantom panes in different windows

    • Create a new window with 3 vertical panes
    • Save environment, kill server and restore
    • The window is restored with 3 panes but an extra phantom pane is added to another window!
    • This is intermittent, it happens around 15% of the time.
  3. tmux-resurrect never restored the command to the bottom pane in a 3 window vertical split:

    • Create a new window with 3 vertical panes
    • Run the same script (~script.sh) to each window.
    • Tmux will restore the script to pane 0 and 1, never 2
    • Repeat the test with any script, it is always the bottom that is never restored regardless of the script type
    • This is repeatable every time.

3b. tmux-resurrect never restored the command to the bottom pane in a 3 window vertical split:

  1. tmux-resurrect sometimes remembers the commands of a 4 pane split window

    • Create a new window with 4 vertical panes
    • Each pane has the same script running (~script.sh)
    • Save, kill server and restore
    • tmux-resurrect restores the script to pane 1,2,4 (skips 3)
    • repeat this test 5 times. It always skips pane 3.
    • This is repeatable every time.
  2. tmux-resurrect messes up the position of the windows

    • In a window with 3 evenly spaced vertical panes, around 30% of the time the panes are restored all bunched up at the top.
    • This may be related to adding a pane to another window.
    • This is intermittent (happens around 20% of the time)
  3. tmux-resurrect never remembers history of certain windows.

    • The history of Window 0, pane 0 is never restored, all other windows and panes restore as expected.

There are so many different issues it is hard to track them all. I have never had a successful session completely restored, usually there are 3 or 4 issues that need to be corrected every time.

I would guess there are three main root causes:

  1. A timing issue where sometimes the windows and panes are restore correctly and sometimes they are not. This might account for the intermittent nature of some of the issues.
  2. Adding new panes seems to get tmux-resurrect confused, I think it often tries to restore the contents of the past pane position.
  3. Even if no new panes are added, their are certain window configurations that are never restored properly (3 vertically split , evenly spaced panes) never restored the running command of the third pane.
ioogithub commented 2 years ago

After more extensive testing I have more results to report:

I recreated my session from scratch and I get the same problems as I reported earlier so it is 100% reproducible.

  1. The problems always happen in the last two windows never the first ones. If there are 6 windows it will always be in 5 and 6.
  2. The problem is not consistent. I can take the same save file and restore it 3 times and each time get a different result, each time the restore has one of the following problems:
    • an extra panes is added to the window,
    • panes in the last two windows lose their position and bunch up at the top
    • commands in the last panes of the last two windows are not restored.
  3. I can make a change to any window or pane (i.e. add a new pane to Window 1 or start a new command in Window 3, pane 4) and this somehow corrupts the last few panes.

Initially I thought there was a limit as to how many panes you can have in a session (around 24 spread out over 5 or 6 windows?). Once you go past this, the last few panes are getting corrupted somehow.

It seems to be a buffer or variable issue, like a variable can only store so many characters, after it fills up it is a gamble as to what will be restored at the end.

It could also be a bug like an end of line character is missing somewhere. This would explain why if I make a change to a pane in Window 2 it shifts all windows and panes down by one and the end pane is always corrupted.

I am testing with the latest version 4.0.0.