tmux-plugins / tmux-resurrect

Persists tmux environment across system restarts.
MIT License
11.39k stars 423 forks source link

Catch and prompt action for corrupted resurrect files #403

Open metasoarous opened 3 years ago

metasoarous commented 3 years ago

I just had a problem where all of a sudden running tmux was immediately exiting with [exited]. After a bit of digging around I realized that the ~/.tmux/resurrect/last file was pointing to an empty resurrect file! The fix was easy enough, but it took me quite a while to resolve this and was rather handicapped at the terminal until I did.

I'm not sure why the resurrect file didn't save properly, and it may not even be possible to fix whatever the issue was. But I'm wondering if it would be possible to catch this edge case and present a prompt asking if the user would like to reload a different resurrect (perhaps the most recent non-empty) session. Even a warning that the resurrect file was empty and can't be loaded before exiting (with some tips on how to fix) would have saved me a ton of time. Is this something you'd consider?

Thanks for your time, and the awesome plugin!

ret2src commented 3 years ago

ksnip_20210905-143317

I have exactly the same problem. This issue is especially problematic if you automatically start tmux with your shell because it will prevent you from using your terminal. I think there should be a check that makes tmux-resurrect fail gracefully, e. g. something as simple as displaying a message like "Error: Could not load resurrect file. Starting new session instead ...".

I'm not sure why there are corrupted / zero-byte resurrect files in the first place, though. I think the underlying issue should be fixed as well.

metasoarous commented 3 years ago

Thanks for chiming in @ret2src. Glad I'm not the only one here. (misery loves company?)

I'd be pretty happy with that solution. I can't really think of a situation where I'd want an earlier version of the session (I probably wouldn't even notice). And if someone did, catching the warning would give them enough info to mess around with the last pointer until they get what they want.

I definitely agree that fixing the underlying problem would be nice as well (if possible). In my case, I think there had been a hard reset or battery failure somewhere in the interim, so maybe there were some hanging file handles that didn't get closed out properly?

Thanks again

dmitry-kabanov commented 2 years ago

I got this problem today, when a colleague has restarted a server without noticing others, and now I cannot start tmux (it exits immediately).

ret2src commented 2 years ago

@dmitry-kabanov Delete the corrupted file and you should be good

me2r036 commented 1 year ago

Encountered the same issue today, thanks @metasoarous, you are a life saver.

Myxhf commented 7 months ago
rtmux() {
    cd ~/.local/share/tmux/resurrect/ || exit # Your save path
    find . | sort | tail -n 1 | xargs rm
    find . -printf "%f\n" | sort | tail -n 1 | xargs -I {} ln -sf {} last
    cd - || exit
}

This issue occurs periodically,I solved it with a simple shell command.

florian-bellencontre commented 1 week ago

We have the same problem here: our last file is sometimes empty.

I've tried to diagnose it by trying to save my tmux several times, but I can't reproduce it. It seems to happen before I shut down my computer. The rest of the backups are ok.