helix-editor / helix

A post-modern modal text editor.
https://helix-editor.com
Mozilla Public License 2.0
32.9k stars 2.43k forks source link

Helix freezes when trying to paste via `<space>P` while the system clipboard is empty #5246

Open cor opened 1 year ago

cor commented 1 year ago

Summary

When your system clipboard is empty and you try to paste using <space>P while the system clipboard is empty helix freezes forever.

Reproduction Steps

I tried this:

  1. the system clipboard is empty
  2. hx
  3. <space>p

I expected this to happen: Helix does not freeze

Instead, this happened: Helix freezes

Helix log

2022-12-21T13:12:02.801 helix_view::editor [ERROR] editor error: 1 unsaved buffer(s) remaining: ["[scratch]"]

Platform

Linux

Terminal Emulator

/nix/store/8zfffsihd8nqmi1786k6a6n2lx5ndkw2-kitty-0.26.2/bin/kitty

Helix Version

6ab8591715daf932d0dc45d0d5fb9e5a272f2fe1

the-mikedavis commented 1 year ago

Which clipboard provider are you using? hx --health | head should have a line that says which one

cor commented 1 year ago

Which clipboard provider are you using? hx --health | head should have a line that says which one

@the-mikedavis :

Clipboard provider: xclip
System clipboard provider: xclip

I noticed something interesting, it specifically seems to happen when I first copy something on my host OS (macOS) and then try to past it within my VM (NixOS) where Helix is running. Perhaps the shared clipboard mechanism of my hypervisor (Parallels) may have something to do with it

pascalkuthe commented 1 year ago

We can probably not fix every issue with system clipboard providers. I also run into some freezes when I press middle mouse by accident. I tracked these down to just helix waiting on the clipbaord provider forever.

I will double.check the code again to ensure there are no missed deadlocks but I skvut that. I think we should just await the clipboard providers command with a timeout to avoid locking up the editor in case the command acts up (copy should actually always run in the background). I think this is something we may want do in general for all commands: Make sure that whenever we are shelling out that we are never blocking the UI thread without a timeout.