tmux-resurrect
tmux-resurrect copied to clipboard
Bug: Re-saving session restored by tmux-resurrect corrupts resurrect session file, and makes programs not launch
This one was difficult to debug, but it's simple to reproduce.
Steps:
- Kill tmux-server
>>tmux kill-server, and restart tmux>>tmux. - Create a vertical split so there are two panes. At this point the focus will be in right pane.
- Move the focus to the left pane by clicking mouse on the left pane.
- Launch
>>htopor other program (I also triednvim) in left pane. - Save resurrect session file by pressing
<prefix>Ctrl-s. - Kill tmux-server
>>tmux kill-server, and restart tmux>>tmux. - Restore the session saved in step-5 by pressing
<prefix>Ctrl-r. The session will restore correctly this time, withhtoplaunched in left pane. - Again save resurrect session file by pressing
<prefix>Ctrl-s. - Kill tmux-server
>>tmux kill-server, and restart tmux>>tmux. - Restore the session saved in step-8 by pressing
<prefix>Ctrl-r.
This time htop won't launch automatically in left pane!
I compared the files saved by tmux-resurrect in step 5, step 8. They are different, and the difference introduced is the cause of this bug. Here are the contents of the file ~/.tmux/resurrect/last after step-5, and step-8:
After step-5:
pane 0 1 :zsh... 1 :* 1 :/Users/reportaman/.tmux/plugins/tmux-resurrect 1 htop :htop
-zsh
pane 0 1 :zsh... 1 :* 2 :/Users/reportaman/.tmux/plugins/tmux-resurrect 0 zsh :-zsh
window 0 1 1 :* 2280,288x76,0,0{144x76,0,0,0,143x76,145,0,1}
state 0
After step-8:
pane 0 1 :zsh... 1 :* 1 :/Users/reportaman/.tmux/plugins/tmux-resurrect 1 htop :-zsh
htop
pane 0 1 :zsh... 1 :* 2 :/Users/reportaman/.tmux/plugins/tmux-resurrect 0 zsh :-zsh
window 0 1 1 :* a281,288x76,0,0{144x76,0,0,1,143x76,145,0,2}
state 0
There seem to be two problems:
-
On first and second line, the programs htop & zsh got swapped.
-
On line four
2280becamea281, and145,0,1}became145,0,2}. Not sure what this is.
There seem to be old bugs that complain about programs not launching correctly, in this one I give simple steps to reproduce & source of the problem. Hopefully this will get resolved sooner than later :) it will make tmux-resurrect reliable!
I followed the repro steps and I can't reproduce the bug. However, I do believe you're getting a bug, but it's probably due to something else in your (and other users') environment.
I propose you try to figure it out. PR with a fix would be welcome!
@bruno- Are you setting any variable related to tmux-resurrect in tmux.conf file? I had just one, and commenting that also doesn't do anything different.
Perhaps you have more elaborate settings related to tmux-resurrect? Can you give it a try by disabling them if thats true? Btw, the bug is not reproducible if the process is started in right pane instead of left.
set -g @resurrect-processes ' \
"~nvim->nvim" \
'
Some system information:
OS: macOS 11.4 BigSur
Architecture: ARM-64
Terminal: iTerm2 or Alacritty
Shell zsh 5.8
Bash version: GNU bash, version 5.1.8(1)-release (aarch64-apple-darwin20.4.0)
Also, can you post your entire tmux.conf file? It would also help to understand the format of resurrect file. Like what's the line with -zsh (on line 2) (I guess that is the parent process).
@bruno- I debugged further, and this is what is happening:
Firstly, I am using the default save strategy, "ps". I am not sure what save strategy you are using?
The problem seems to stem from the following statement in file https://github.com/tmux-plugins/tmux-resurrect/blob/master/save_command_strategies/ps.sh
ps -ao "ppid command" |
sed "s/^ *//" |
grep "^${PANE_PID}" |
cut -d' ' -f2-
During first resurrect save it returns
htop
-zsh
After reloading resurrect session, and upon resurrect save again it returns:
-zsh
htop
The order is reversed, any thoughts of what this means?
@bruno- I think I fixed it! Adding a final piped grep to the ps command grep -v -e "^-.*" resolves the problem. It removed lines for login shell -zsh.
ps -ao "ppid command" |
sed "s/^ *//" |
grep "^${PANE_PID}" |
cut -d' ' -f2- |
grep -v -e "^-.*"
Now every time the resurrect session file is saved like this:
pane 0 1 :zsh... 1 :* 1 :/Users/amanmehra 1 htop :htop
pane 0 1 :zsh... 1 :* 2 :/Users/amanmehra 0 zsh :
window 0 1 1 :* c920,300x76,0,0{150x76,0,0,1,149x76,151,0,2}
state 0
Please review, and let me know what you think. Then I will submit a PR.
Updated the command above from grep -v -e "-." to grep -v -e "^-.". Can be further refined to just catch login processes like
--zsh,-bash, etc.