Prevent ctags process stacking on stucked .tags.kaklock folder#5408
Prevent ctags process stacking on stucked .tags.kaklock folder#5408stacyharper wants to merge 1 commit intomawww:masterfrom
Conversation
I'm not sure to fully understand what is causing this, but it happened to me multiple time. A new process get stuck on every buffer save, and I discover at the end of the day that a hundred of them are stucked. At least let's try to remove the lock folder when starting Kakoune.
| declare-option -docstring "path to the directory in which the tags file will be generated" str ctagspaths "." | ||
|
|
||
| hook global EnterDirectory .* %{ nop %sh{ [ -d .tags.kaklock ] && rmdir .tags.kaklock } } | ||
|
|
There was a problem hiding this comment.
probably it gets stuck in
while ! mkdir .tags.kaklock 2>/dev/null; do sleep 1; done
how about mkdir -p .tags.kaklock || exit ? Maybe also check git blame info for this line
There was a problem hiding this comment.
The goal for this line is of course to prevent race condition. But in some situations, the folder remains after Kakoune exit. Maybe the folder does not get cleaned up in some cases. I'm not sure. At least with this patch, the folder get cleaned up with a future instance of Kakoune.
|
Not sure if we should remove that lock file on startup, some people use multiple Kakoune sessions in the same project and this change would break that use case. Investigating what cases lead to the file still existing would be good, as we currently remove it with |
|
the process would never exit, because it wait for the lock. Does the shell process is killed by Kakoune when exiting? Maybe we should add some signals to this trap? |
|
The new process yeah, what I am trying to understand is why the old process exited without removing the lock, or maybe it is actually still running ? |
|
because I quited Kakoune while ctags was running? meaning the shell get killed just after ctags, without entering the trap |
|
Should'nt the trap run in this case ? Doing some quick testing here, EXIT traps seem to run on SIGTERM and SIGINT, it does not on SIGKILL but I would be surprised for this shell script to get SIGKILL'd. |
|
I got this simple config. What happen when we ":wq" in a large code base folder? The shell being killed without trapping seems the only way for this issues to occurs to me |
|
Testing here this is what I get: So, as far as |
|
I reproduce your outputs here, and I also don't see how this can happen. In this "wq" situation, the script is updating ctags, meaning it only generates ctags for one buffer. So no, this should always run fast. The only way I can think about is, if I run "ctags-generate" and then I poweroff the machine immediately. Even if the poweroffing would take some time, a signal might already have killed the shell process, preventing the EXIT trap to run. I replaced this hook by a debug warning, and will try to check the debug buffer often. |
|
I think I got something. The fact that kakoune does not kill its shell instances, and that we don't trap those signals in them, might still cause issues. Kakoune might be killed using its process group, meaning all its sub-process will also receive the kill signal. In this situation, this would cause the bug because the script would handle the signal just after the ctags completion, and will never reach EXIT. I also think this concretely happen when the terminal emulator is being killed. If I run "ctags-generate", and then I kill my Foot instance, the lock folder is never removed. edit: I confirm this happen if kakoune is being killed by process group. Reproduction: run two terminals, one prepare a kakoune instance in a big codebase folder, with ":ctags-generate" prepared. In another terminal, run |
|
This is weird, Testing here, with the previous script and making the delay longer, I see the sleep process staying alive after closing the foot window that has Kakoune running directly. How do you kill foot ? |
|
There is not trap for TERM, so the script is just stopped early, and the EXIT trap is never reached. This is something easily reproductible with some script as: #!/bin/sh
trap "notify-send foo" EXIT
sleep 5Then kill this script while sleeping. It does not run the notify-send. So imho the scripts that use some lock mechanisms should always handle this signal to prevent those unrecoverable situations. Either because Kakoune would signal it when it stops, because of a process group signal propagation, or just because all process have to stop (poweroff). I'm not sure if we should propagate the signal to the child ctags process. Probably this is not necessary. edit:
I use my Sway "kill" keybind to kill the window. |
|
Hum, which shell are you using ? Doing some testing here it seems the EXIT trap runs in bash but not in dash when closing the terminal directly from sway. |
|
https://pubs.opengroup.org/onlinepubs/9699919799/ is not very clear on when EXIT should be triggered, both |
|
yeah dash needs something like "trap ... EXIT HUP INT QUIT"
|
That links to the 2018 version of POSIX. The 2024 edition says:
...which I guess just means that both the |
That does not seem to work unfortunately, |
|
I'm using Bash in Foot, and edit: So what does this means for us? What is the most compatible approach? We should probably not trap EXIT, but run the cleanup linearly after the ctags cmd. And trap signals to finish early? |
I'm not sure to fully understand what is causing this, but it happened to me multiple time. A new process get stuck on every buffer save, and I discover at the end of the day that a hundred of them are stucked.
At least let's try to remove the lock folder when starting Kakoune.