tmux-plugins / tmux-resurrect

Persists tmux environment across system restarts.
MIT License
11.25k stars 420 forks source link

C-r Restore Exiting #122

Open cwervo opened 8 years ago

cwervo commented 8 years ago

Tmux was working fine until a few weeks ago when I suddenly started getting exiting (not errors) when using C-r to try and restore. C-s still works, writes to the symlink last and everything seems to be okay, but when I try to resurrect even the simplest setup:

pane    0   1   :which  1   :*  1   :/Users/tiny/.tmux/plugins/tmux-resurrect   1   zsh :-zsh
window  0   1   1   :*  b9bd,158x52,0,0,0
state   0   

I just end up outside tmux looking at:

[exited]

And the session has been killed (i.e. exited out) and I have no other error or warning information.

bruno- commented 8 years ago

Hm.. this is pretty weird.

Which tmux version are you running? Is it like the "absolute latest built from source" or something?

cwervo commented 8 years ago

It's the homebrew version of tmux, which, to my understanding, isn't on the be bleeding edge. Since tmux hasn't updated, might it be interference with zsh, which has had a few updates recently?

cwervo commented 8 years ago

Hmm, no, I changed my shell to bash and the problem persists.

wingy3181 commented 7 years ago

Thought I might add my 2 cents.

I had exactly the same issue for a few months (thinking maybe an update to tmux from brew or an update to this tmux-resurrect plugin would eventually fix the issue)

When I had the following flag: set -g @resurrect-capture-pane-contents 'on' it would exit on restore.

Eventually traced through the shell script for restoration (https://github.com/tmux-plugins/tmux-resurrect/blob/master/scripts/restore.sh)

and traced it to the function pane_creation_command() where it executes the tmux default command (https://github.com/tmux-plugins/tmux-resurrect/blob/master/scripts/restore.sh#L111)

Turns out I had the following in my .tmux.conf file : set-option -g default-command "exec reattach-to-user-namespace -l $SHELL which resolved to: cat '~/.tmux/resurrect/pane_contents//pane-0:1.1'; exec exec reattach-to-user-namespace -l /usr/local/bin/bash This was to get pbcopy and pbpaste working in tmux (from https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard)

Notice the double exec In the end I just changed my .tmux.conf to: set-option -g default-command "reattach-to-user-namespace -l $SHELL"

Seems to work now although some of the custom window names seem to go back to default Can live without that though.. a lot better than before when it was just exiting out after attempting to restore.

shawn-g-hu commented 5 years ago

EDIT: I fixed this issue. It had to do with a path issue which was caused when mounting a directory into the docker container. My homedir was a subdirectory of a symlink, so in my main system there were two valid paths to ~ (and in particular, to the files that resurrect used to recreate my session). When I mounted my homedir into the docker container, the path that resurrect used became invalid, so my various panes couldn't be restored.

Bumping this issue to say that I'm encountering similar behavior, on tmux 2.1. However, it only occurs for me in an interaction with docker: Only if I save a file outside a docker container, and try to restore it inside the container (the only combination I really want), do I get this crash. I can save a file inside the container and restore it inside, save inside and restore outside, and save outside and restore outside, all just fine. Whether inside or outside the container, it appears that ctrl-S correctly saves the session to last. I've tried this both with and without continuum installed.

Another interesting behavior is that I only get a crash if I attempt to restore in a new session- I imagine this has to do with the new session special case ("The single exception to this is when tmux is started with only 1 pane in order to restore previous tmux env. Only in this case will this single pane be overwritten. "). If I try to restore from an existing session, I'll get the restore message in the status bar but my tmux session will remain the same (no changes).

This behavior seems pretty similar to https://github.com/tmux-plugins/tmux-resurrect/issues/91, and also a bit like https://github.com/tmux-plugins/tmux-resurrect/issues/98, but the fixes for these haven't worked for me (in particular, no default command to break things).

Example restore file that this behavior occurs on:

pane    0   1   :bash   0   :-  1   :/work/home/shawnghu    1   bash    :                                                                                                                                       
pane    0   2   :bash   1   :*  1   :/work/home/shawnghu    0   bash    :   
pane    0   2   :bash   1   :*  2   :/work/home/shawnghu    1   bash    :   
window  0   1   0   :-  b29d,208x60,0,0,0
window  0   2   1   :*  f41d,208x60,0,0{104x60,0,0,1,103x60,105,0,2}
state   0   

Output of show-options -g:

@copycat_search_C-d "[[:digit:]]+"                                                                                                                                                                         [0/0]
@copycat_search_C-f "(^|^\.|[[:space:]]|[[:space:]]\.|[[:space:]]\.\.|^\.\.)[[:alnum:]~_-]*/[][[:alnum:]_.#$%&+=/@-]*"
@copycat_search_C-u "(https?://|git@|git://|ssh://|ftp://|file:///)[[:alnum:]?=%/_.:,;~@!#$&()*+-]*"
@copycat_search_M-h "\b[0-9a-f]{7,40}\b"
@copycat_search_M-i "[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}"
@plugin "nhdaly/tmux-better-mouse-mode"
@resurrect-restore-script-path "/home/shawnghu/.tmux/plugins/tmux-resurrect/scripts/restore.sh"
@resurrect-save-script-path "/home/shawnghu/.tmux/plugins/tmux-resurrect/scripts/save.sh"
@resurrect-strategy-irb "default_strategy"
assume-paste-time 1
base-index 1
bell-action any
bell-on-alert off
default-command ""
default-shell "/bin/bash"
destroy-unattached off
detach-on-destroy on
display-panes-active-colour red
display-panes-colour blue
display-panes-time 1000
display-time 4000
history-limit 30000
lock-after-time 0
lock-command "lock -np"
message-command-style fg=yellow,bg=black
message-style fg=black,bg=yellow
mouse on
mouse-utf8 on
prefix C-b
prefix2 <NONE>
renumber-windows off
repeat-time 500
set-remain-on-exit off
set-titles off
set-titles-string "#S:#I:#W - "#T" #{session_alerts}"
status on
status-interval 5
status-justify left
status-keys emacs
status-left "[#S] "
status-left-length 100
status-left-style default
status-position bottom
status-right " "#{=21:pane_title}" %H:%M %d-%b-%y"
status-right-length 40
status-right-style default
status-style fg=black,bg=green
status-utf8 on
update-environment "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"
visual-activity off
visual-bell off
visual-silence off
word-separators " -_@"

My .tmux.conf (messy):

set -g base-index 1
set -g pane-base-index 1
set -g status-left-length 100

#set -g default-terminal "tmux-256color" 
#set -g default-terminal "xterm-256color"
set -g default-terminal "screen-256color"
#set-window-option -g xterm-keys on
unbind \;
unbind :
bind : last-pane
bind \; command

# allows for native xterm scrolling behavior
set -g terminal-overrides 'xterm*:smcup@:rmcup@' 

# Make mouse useful in copy mode
setw -g mouse on

# Allow mouse to select which pane to use
#set -g mouse-select-pane on

# Allow xterm titles in terminal window, terminal scrolling with scrollbar, and setting overrides of C-Up, C-Down, C-Left, C-Right
#set -g terminal-overrides "xterm*:XT:smcup@:rmcup@:kUP5=\eOA:kDN5=\eOB:kLFT5=\eOD:kRIT5=\eOC"

# Scroll History
set -g history-limit 30000

# Set ability to capture on start and restore on exit window data when running an application
setw -g alternate-screen on

# Lower escape timing from 500ms to 50ms for quicker response to scroll-buffer access.
set -s escape-time 50

bind -n WheelUpPane if "[[ #{pane_current_command} =~ vim ]]" "select-pane -t = ; send-keys -M" "select-pane -t = ; send-keys Up"
bind -n WheelDownPane if "[[ #{pane_current_command} =~ vim ]]" "select-pane -t = ; send-keys -M" "select-pane -t = ; send-keys Down"

bind S source-file ~/.tmux/simultaneous_visualization
bind T source-file ~/.tmux/lidar_perception

#reload tmux session upon server start
#set -g @continuum-restore 'on'

# Use Alt-vim keys without prefix key to switch panes
bind -n M-h select-pane -L
bind -n M-j select-pane -D 
bind -n M-k select-pane -U
bind -n M-l select-pane -R

# Use Alt-arrow keys without prefix key to switch panes
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

#Pane colours
#-------------------------------------------------------#
# set inactive/active window styles
#set -g window-style 'fg=colour247,bg=colour236'
#set -g window-active-style 'fg=colour250,bg=black'

#pane border
#set -g pane-border-bg colour235
#set -g pane-border-fg colour238
#set -g pane-active-border-bg colour236
#set -g pane-active-border-fg colour51

#hack to fix tmux resurrect inside docker containers
#bind C-s run-shell ~/.tmux/plugins/tmux-resurrect/scripts/save.sh
#bind C-r run-shell ~/.tmux/plugins/tmux-resurrect/scripts/restore.sh

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
#set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @plugin 'tmux-plugins/tmux-copycat'
set -g @plugin 'tmux-plugins/tmux-yank'

set -g @plugin 'nhdaly/tmux-better-mouse-mode'

# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'git@github.com/user/plugin'
# set -g @plugin 'git@bitbucket.com/user/plugin'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
nickjj commented 3 years ago

I saw this today for the first time after years of using tmux / tmux-resurrect without issues. I'm running 3.0a from the Ubuntu 20.04 official apt package running inside of WSL 2.

I'm not 100% sure on this but I think this happens if the symlink to last is pointing to a file that's 0 bytes. I was able to fix the problem by manually symlinking last to the most recent non-empty restore txt file.

You can check / fix this by:

  1. Goto cd ~/.tmux/resurrect
  2. Run ls -la
  3. Check to see if last is pointing to a 0 byte file
  4. If so, look for the latest non-empty restore txt file and copy its file name
  5. Run ln -sf $LASTEST_NON_EMPTY_FILE last to update last to your latest non-empty file
  6. Launch tmux
  7. Restore with leader + CTRL + r

I don't know how the most recent version of a resurrect restore file ended up being 0 bytes but the above let me restore from a fairly recent save and it no longer immediately exit out with [exited].