mawww / kakoune

mawww's experiment for a better code editor
http://kakoune.org
The Unlicense
9.94k stars 716 forks source link

Kakoune freezing when deleting character in normal mode #869

Closed jkonecny12 closed 8 years ago

jkonecny12 commented 8 years ago

This bug has some race condition, I can't reproduce it normally. I just got it 2 times in a few days. First it was when I edited git commit message and now in normal file edit.

Here is the backtrace:


    (gdb) bt
    #0  0x00007f68ea606241 in pselect () from /lib64/libc.so.6
    #1  0x000000000082bfd8 in Kakoune::EventManager::handle_next_events(Kakoune::EventMode, __sigset_t*) ()
    #2  0x00000000008b9803 in Kakoune::ShellManager::eval(Kakoune::StringView, Kakoune::Context const&, Kakoune::StringView, Kakoune::ShellManager::Flags, Kakoune::ShellContext const&) ()
    #3  0x00000000008ab28e in Kakoune::(anonymous namespace)::expand_token(Kakoune::Token const&, Kakoune::Context const&, Kakoune::ShellContext const&) ()
    #4  0x00000000008ac5d0 in Kakoune::CommandManager::execute(Kakoune::StringView, Kakoune::Context&, Kakoune::ShellContext const&) ()
    #5  0x000000000076e7f8 in Kakoune::(anonymous namespace)::{lambda(Kakoune::ParametersParser const&, Kakoune::Context&, Kakoune::ShellContext const&)#14}::operator()(Kakoune::ParametersParser const&, Kakoune::Context&, Kakoune::ShellContext const&) const::{lambda(Kakoune::StringView, Kakoune::Context&)#1}::operator()(Kakoune::(anonymous namespace)::{lambda(Kakoune::ParametersParser const&, Kakoune::Context&, Kakoune::ShellContext const&)#14}, Kakoune::Context&) const ()
    #6  0x0000000000781856 in std::_Function_handler<void (Kakoune::StringView, Kakoune::Context&), Kakoune::(anonymous namespace)::{lambda(Kakoune::ParametersParser const&, Kakoune::Context&, Kakoune::ShellContext const&)#14}::operator()(Kakoune::ParametersParser const&, Kakoune::Context&, Kakoune::ShellContext const&) const::{lambda(Kakoune::StringView, Kakoune::Context&)#1}>::_M_invoke(std::_Any_data const&, Kakoune::StringView&&, Kakoune::Context&) ()
    #7  0x000000000070996c in std::function<void (Kakoune::StringView, Kakoune::Context&)>::operator()(Kakoune::StringView, Kakoune::Context&) const ()
    #8  0x0000000000706f8e in Kakoune::HookManager::run_hook(Kakoune::StringView, Kakoune::StringView, Kakoune::Context&) const ()
    #9  0x00000000007069b0 in Kakoune::HookManager::run_hook(Kakoune::StringView, Kakoune::StringView, Kakoune::Context&) const ()
    #10 0x00000000007069b0 in Kakoune::HookManager::run_hook(Kakoune::StringView, Kakoune::StringView, Kakoune::Context&) const ()
    #11 0x00000000008172b0 in Kakoune::InputModes::Normal::on_key(Kakoune::Key) ()
    #12 0x0000000000815a00 in Kakoune::InputMode::handle_key(Kakoune::Key) ()
    #13 0x0000000000814290 in Kakoune::InputHandler::handle_key(Kakoune::Key) ()
    #14 0x00000000007440a7 in Kakoune::Client::handle_available_input(Kakoune::EventMode) ()
    #15 0x0000000000743593 in Kakoune::Client::Client(std::unique_ptr<Kakoune::UserInterface, std::default_delete<Kakoune::UserInterface> >&&, std::unique_ptr<Kakoune::Window, std::default_delete<Kakoune::Window> >&&, Kakoune::SelectionList, Kakoune::IdMap<Kakoune::String, (Kakoune::MemoryDomain)12>, Kakoune::String)::{lambda(Kakoune::EventMode)#1}::operator()(Kakoune::EventMode) const ()
    #16 0x0000000000747354 in std::_Function_handler<void (Kakoune::EventMode), Kakoune::Client::Client(std::unique_ptr<Kakoune::UserInterface, std::default_delete<Kakoune::UserInterface> >&&, std::unique_ptr<Kakoune::Window, std::default_delete<Kakoune::Window> >&&, Kakoune::SelectionList, Kakoune::IdMap<Kakoune::String, (Kakoune::MemoryDomain)12>, Kakoune::String)::{lambda(Kakoune::EventMode)#1}>::_M_invoke(std::_Any_data const&, Kakoune::EventMode&&) ()
    #17 0x00000000007dc452 in std::function<void (Kakoune::EventMode)>::operator()(Kakoune::EventMode) const
        ()
    #18 0x000000000080371b in Kakoune::NCursesUI::NCursesUI()::{lambda(Kakoune::FDWatcher&, Kakoune::EventMode)#1}::operator()(Kakoune::FDWatcher&, Kakoune::EventMode) const ()
    #19 0x000000000080c6a5 in std::_Function_handler<void (Kakoune::FDWatcher&, Kakoune::EventMode), Kakoune::NCursesUI::NCursesUI()::{lambda(Kakoune::FDWatcher&, Kakoune::EventMode)#1}>::_M_invoke(std::_Any_data const&, Kakoune::FDWatcher&, Kakoune::EventMode&&) ()
    #20 0x000000000082cc86 in std::function<void (Kakoune::FDWatcher&, Kakoune::EventMode)>::operator()(Kakoune::FDWatcher&, Kakoune::EventMode) const ()
    #21 0x000000000082b915 in Kakoune::FDWatcher::run(Kakoune::EventMode) ()
    #22 0x000000000082c1c9 in Kakoune::EventManager::handle_next_events(Kakoune::EventMode, __sigset_t*) ()
    #23 0x000000000083cf4e in run_server(Kakoune::StringView, Kakoune::StringView, bool, bool, bool, UIType, Kakoune::ArrayView<Kakoune::StringView const>, Kakoune::BufferCoord) ()

In the first case I did killall kak and when I run it again I was in the same situation. I tried it a few more times with the same result. However when I changed editor in git, edit, set it back to kakoune, it was fine again.

jkonecny12 commented 8 years ago

When I was deleting line in a file this happened again.

I have this in pstree

        |         |-tmux-+-bash---kak---sh---xsel
        |         |      |-bash
        |         |      |-bash---kak
        |         |      |-bash-+-less
        |         |      |      `-sudo---pstree
        |         |      `-bash---gdb---7*[{gdb}]

Based on this, it looks like there could be problem with my hook on saving clipboard:

# yank to system clipboard always
hook global NormalKey y|d|c %{ nop %sh{
   echo "$kak_selection" | xsel --input
}}

But it worked without a problem for some time. Was there some changes recently in this behavior?

mawww commented 8 years ago

Not sure how xsel behaves, but if xsel is still running, Kakoune cant do much until it exits if you use a %sh{ ... } block.

You might be able to fix the problem by using <a-|> instead, that explicitely does not read the command output:

hook global NormalKey y|d|c %{ exec -draft <space><a-|>xsel<space>--input<ret> }
jkonecny12 commented 8 years ago

I'll try that. Thank you.

casimir commented 8 years ago

Not sure if this is the same bug but I have kakoune freezing when using xsel from a mapping. It doesn't respond to <C-c>.

This occurs randomly when using this mapping:

decl str pastecmd %sh{ which pbpaste > /dev/null && echo 'pbpaste' || echo "'xsel --clipboard --input'" }
map global user p '!$kak_opt_pastecmd<ret>'

Some informations I gathered, hope this helps:

$ cat -e cmdline
xsel^@--clipboard^@--input^@%
(gdb) bt
#0  0x00007f6e9bb394d0 in __read_nocancel () from /usr/lib/libc.so.6
#1  0x00007f6e9c6d2a6e in _nc_wgetch () from /usr/lib/libncursesw.so.6
#2  0x00007f6e9c6d3225 in wgetch () from /usr/lib/libncursesw.so.6
#3  0x00000000004fc86d in Kakoune::NCursesUI::get_key() ()
#4  0x0000000000492322 in Kakoune::Client::handle_available_input(Kakoune::EventMode) ()
#5  0x00000000004fbc79 in ?? ()
#6  0x0000000000514602 in Kakoune::EventManager::handle_next_events(Kakoune::EventMode, __sigset_t*) ()
#7  0x000000000056192b in Kakoune::ShellManager::eval(Kakoune::StringView, Kakoune::Context const&, Kakoune::StringView, Kakoune::ShellManager::Flags, Kakoune::ShellContext const&) ()
#8  0x000000000053a0a9 in void Kakoune::insert_output<(Kakoune::InsertMode)0>(Kakoune::Context&, Kakoune::NormalParams)::{lambda(Kakoune::StringView, Kakoune::PromptEvent, Kakoune::Context&)#1}::operator()(Kakoune::StringView, Kakoune::PromptEvent, Kakoune::Context&) const ()
#9  0x0000000000511f8d in Kakoune::InputModes::Prompt::on_key(Kakoune::Key) ()
#10 0x00000000005039c6 in Kakoune::InputHandler::handle_key(Kakoune::Key) ()
#11 0x000000000052e23b in ?? ()
#12 0x00000000005070c1 in Kakoune::InputModes::NextKey::on_key(Kakoune::Key) ()
#13 0x00000000005039c6 in Kakoune::InputHandler::handle_key(Kakoune::Key) ()
#14 0x0000000000492103 in Kakoune::Client::handle_available_input(Kakoune::EventMode) ()
#15 0x00000000004fbc79 in ?? ()
#16 0x0000000000514602 in Kakoune::EventManager::handle_next_events(Kakoune::EventMode, __sigset_t*) ()
#17 0x0000000000523874 in run_server(Kakoune::StringView, Kakoune::StringView, bool, bool, bool, UIType, Kakoune::ArrayView<Kakoune::StringView const>, Kakoune::BufferCoord) ()
#18 0x0000000000460872 in main ()

screenshot

casimir commented 8 years ago

Zero problem with pastecmd set to xsel.

lenormf commented 8 years ago

Is that really how you declared the mapping, or is it just pseudo code?

mawww commented 8 years ago

frankly, that looks like a bug in xsel, or if not a bug, an unexpected behaviour. Kakoune wrote to a pipe connected to xsel stdin, then closed it, but in lsof seems stdin for xsel is now the terminal, which would suggest xsel reopened it itself. I think we'd need to explore xsel code to understand whats going on here, but its strange that this tool wont just read from stdin until closed, copy whatever came into the X11 clipboard and exit immediately.

casimir commented 8 years ago

Update after a few hours of usage, xsel (without arguments) does the job perfectly. It really looks like --input and --output are inconstants, either by documentation or by behaviour. In short I don't think this is kakoune's fault, like @mawww says.

@lenormf this is the actual commands (extracted from my kakrc).

jkonecny12 commented 8 years ago

@casimir are you running on Wayland or Xorg? I've changed to Wayland recently so I'm thinking if that can be the issue here.

casimir commented 8 years ago

Awesome isn't compatible with Wayland but I don't have xorg-xserver installed. I guess I use XWayland.

mawww commented 8 years ago

I think we established this is not a Kakoune bug, but a strange behaviour of xsel. Reopen if there is something new.