这是indexloc提供的服务,不要输入任何密码
Skip to content

Temporal session file is deleted after detaching #135

@greymd

Description

@greymd

Reported in #114 (comment)

The session file is automatically deleted when tmux session is detached.
I imagine it must be helpful for users if the session file is kept in that case.
Because, in a common case, the user does not recognize the possibility that the session is better to be kept alive when opening the new windows.

How to reproduce

(1) Create session from outside of tmux session.

$ xpanes --ssh localhost

(2) Detach the session (ctrl+b and d by default)

(3) Session is alive but session file is deleted.

$ ps alx | grep tmux
1  1000 20005     1  20   0  27648  4032 poll_s Ss   ?          0:00 tmux -S /home/ubuntu/.cache/xpanes/socket.19931 new-session -s xpanes-19931 -n tmp-19931 -d /usr/bin/xpanes '--ssh' '-c' 'ssh -o StrictHostKeyChecking=no {} '  '--' 'localhost'

$ ls /home/ubuntu/.cache/xpanes/socket.19931
ls: cannot access '/home/ubuntu/.cache/xpanes/socket.19931': No such file or directory

Technical reason

This is caused by this trap.

trap 'rm -f "${XP_CACHE_HOME}"/__xpns_*$$; rm -f "${XP_DEFAULT_SOCKET_PATH}"' EXIT

$ bash -x xpanes -c 'ssh {}' localhost localhost
+ readonly 'XP_SHELL=/usr/bin/env bash'
...
+ tmux -S /home/ubuntu/.cache/xpanes/socket.9635 attach-session -t xpanes-9635
[detached (from session xpanes-9635)]
+ exit 0
+ rm -f '/home/ubuntu/.cache/xpanes/__xpns_*9635'
+ rm -f /home/ubuntu/.cache/xpanes/socket.9635

The temporal session file ~/.cache/xpanes/socket.<PID> is supposed to be used to recover the session.
So, the file may be kept in case of network disconnection or any other troubles.
On the other hand, the file is going to be deleted if the tmux session is explicitly exited because any recovery won't be required.

However, tmux also makes its own process exit when detaching (ctrl+b d).
As far as investigated, there is no way for xpanes to confirm whether the session is "explicitly exited" or "detached". This is the reason why xpanes deletes the session file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions