ludovicchabant / vim-gutentags

A Vim plugin that manages your tag files
https://bolt80.com/gutentags/
MIT License
2.3k stars 175 forks source link

Don't terminate jobs on exit #248

Closed yukunlin closed 4 years ago

yukunlin commented 5 years ago

Terminating jobs on exit can lead to race conditions with :x on a changed buffer. In that scenario, the job updating the tags file can be prematurely terminated when vim exits.

This issue started happening for me after updating to neovim 0.4.2. Error message after executing :x on a changed file, with let g:gutentags_trace=1.

gutentags: [job output]: ['Locking tags file...', 'Removing references to: foo.py', 'grep --text -Ev ''^[^^I]+^Ifoo.py^I'' ''.tags'' > ''.tags.temp''', 'Running ctags on "foo.py"', 'ctags -f ".tags.temp"  --options=/Users/yukun/vim-gutentags/res/ctags_recursive.options --exclude=@/var/folders/dj/plng1rzs6910gyws3tchvbn00000gn/T/nvimFifjdn/1 --append "foo.py"', 'Replacing tags file', 'mv -f ".tags.temp" ".tags"', '']
gutentags: Finished ctags job.
gutentags: ctags job failed, returned: 141% 

I suspect it's due to some changes between neovim and 0.3.8 and 0.4.2 that changed the timing of events that lead to jobs being terminated earlier on exit than before. The error code indicates failure from being killed by a signal (https://neovim.io/doc/user/job_control.html#on_exit).

ludovicchabant commented 4 years ago

The thing I'm worried about is that if we don't terminate jobs on exit, you could open Vim on a big project (launching a job), then you quit (the job keeps working), and then yo re-open Vim in the same project (launching a job). Now you've got 2 different processes reading from and writing to the same files, and that can't be good...

Ideally we would know that we are going to exit after writing the buffer, so we wouldn't trigger the job in the first place, but I can't think of a way to do that...

If the problem here is that it displays an error on exit, we can try to shut gutentags up with something like this maybe? https://gist.github.com/ludovicchabant/b3e0477d38d7817fac64d08944f03a35

ludovicchabant commented 4 years ago

The error message you mentioned is now suppressed. Thanks!