tpope / vim-obsession

obsession.vim: continuously updated session files
http://www.vim.org/scripts/script.php?script_id=4472
1.76k stars 70 forks source link

session tmpfiles are not cleaned up #72

Closed r10r closed 2 years ago

r10r commented 2 years ago

Hi @tpope

I've just installed the latest version of vim-obsession d2818a614ec3a5d174c6bb19e87e2eeb207f4900 and noticed that the session tmp files of the format {sessionname}.obsession.{pid} are not cleaned up.

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Apr 01 2022 10:43:42)
Included patches: 1-4619
Compiled by Alpine Linux
Huge version without GUI.  Features included (+) or not (-):
+acl               +file_in_path      +mouse_urxvt       -tag_any_white
+arabic            +find_in_path      +mouse_xterm       -tcl
+autocmd           +float             +multi_byte        +termguicolors
+autochdir         +folding           +multi_lang        +terminal
-autoservername    -footer            -mzscheme          +terminfo
-balloon_eval      +fork()            +netbeans_intg     +termresponse
+balloon_eval_term -gettext           +num64             +textobjects
-browse            -hangul_input      +packages          +textprop
++builtin_terms    +iconv             +path_extra        +timers
+byte_offset       +insert_expand     -perl              +title
+channel           +ipv6              +persistent_undo   -toolbar
+cindent           +job               +popupwin          +user_commands
-clientserver      +jumplist          +postscript        +vartabs
-clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +vim9script
+cmdline_hist      +langmap           -python            +viminfo
+cmdline_info      +libcall           +python3/dyn       +virtualedit
+comments          +linebreak         +quickfix          +visual
+conceal           +lispindent        +reltime           +visualextra
+cryptv            +listcmds          +rightleft         +vreplace
+cscope            +localmap          -ruby              +wildignore
+cursorbind        +lua               +scrollbind        +wildmenu
+cursorshape       +menu              +signs             +windows
+dialog_con        +mksession         +smartindent       +writebackup
+diff              +modify_fname      -sodium            -X11
+digraphs          +mouse             -sound             -xfontset
-dnd               -mouseshape        +spell             -xim
-ebcdic            +mouse_dec         +startuptime       -xpm
+emacs_tags        -mouse_gpm         +statusline        -xsmp
+eval              -mouse_jsbterm     -sun_workshop      -xterm_clipboard
+ex_extra          +mouse_netterm     +syntax            -xterm_save
+extra_search      +mouse_sgr         +tag_binary        
-farsi             -mouse_sysmouse    -tag_old_static    
   system vimrc file: "/etc/vim/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -Os -fomit-frame-pointer -Os -fomit-frame-pointer -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 
Linking: gcc -L/usr/local/lib -Wl,--as-needed -o vim -lm -lncurses -L/usr/lua5.3/lib -llua 
tpope commented 2 years ago

This line should effectively clean them up:

https://github.com/tpope/vim-obsession/blob/d2818a614ec3a5d174c6bb19e87e2eeb207f4900/plugin/obsession.vim#L85

I can't reproduce, so I'll need a bit more of a clue about the circumstances under which this problem happens.

r10r commented 2 years ago

I've just done an strace, and it seems that the session gets written again. When I disable all other plugins it works as expected.

close(3)                                = 0                                                                                        
stat("/root/devcontainer/Session.vim.obsession.12567", {st_mode=S_IFREG|0644, st_size=1242, ...}) = 0                              
stat("/root/devcontainer/Session.vim", {st_mode=S_IFREG|0644, st_size=1242, ...}) = 0                                              
unlink("/root/devcontainer/Session.vim") = 0                                                                                       
rename("/root/devcontainer/Session.vim.obsession.12567", "/root/devcontainer/Session.vim") = 0                                     
mmap(NULL, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fdc27615000                                         
[...]
stat("/root/devcontainer/Session.vim.obsession.12567", 0x7ffda27e3ca0) = -1 ENOENT (No such file or directory)
open("/root/devcontainer/Session.vim.obsession.12567", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
r10r commented 2 years ago

I nailed it down to the coc.nvim plugin

r10r commented 2 years ago

The only hint regarding sessions in coc.nvim is https://github.com/neoclide/coc.nvim/blob/a2dc06d0d44addf37a8e0d7bf7b4b1258302262a/doc/coc.txt#L1855

tpope commented 2 years ago

I did that push before seeing your most recent comments. Still gonna cross my fingers that it's an effective fix.

That coc.nvim doc is just saying that g:WorkspaceFolders could end up in the session. It's passive and shouldn't cause an issue like this.

r10r commented 2 years ago

I think you can revert the change. The culprit is the coc plugin coc-lists

Session handling in coc-lists is enabled by default and must be disabled in :CocConfig with

"session.saveOnVimLeave": "false"

See also https://github.com/neoclide/coc-lists#options

tpope commented 2 years ago

The change will cover a few other possible error conditions so I'll leave it in place. Thanks for sharing your solution.

r10r commented 2 years ago

Thanks for your support!