Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freeze when using "yank" function #25

Closed
lheckemann opened this issue Sep 2, 2021 · 8 comments
Closed

Freeze when using "yank" function #25

lheckemann opened this issue Sep 2, 2021 · 8 comments

Comments

@lheckemann
Copy link

Whenever I use the yank function, the store path is copied to the clipboard correctly, but nix-tree stops responding to any further input. I'm not sure how to debug any further, any suggestions?

@utdemir
Copy link
Owner

utdemir commented Sep 2, 2021

Oh, that's annoying, but I think I have an idea of what might be happening.

Yank functionality is implemented via trying to run a set of shell commands, in this order:

cmds =
[ ("xsel", ["-i", "-b"]),
("xclip", ["-selection", "clipboard"]),
("wl-copy", []),
("pbcopy", [])
]

I have xsel on my system and it works fine for me, but I think you might be using another one which might be configured incorrectly and not terminating, blocking the main thread.

Does it make sense to you? You can try running echo foobar | <cmd> for each of the above comments, and see if they terminate correctly; and if you see something which doesn't work, feel free to comment here or send a PR.

There're things we can do to mitigate this issue freezing the entire app; we can put a timeout to the command, or just run it outside of the main thread. I'll implement one of them, but I'd still appreciate if you could try to spot which command is incorrect.

@utdemir
Copy link
Owner

utdemir commented Sep 4, 2021

I put a timeout on the command for the yank action, which is not a solution but should still be better than freezing (bb77231).

Keeping the issue open since I don't exactly know if this is the problem, and even if it is we still have to figure out why it hangs.

@lheckemann
Copy link
Author

The timeout doesn't work as desired because System.Timeout can only interrupt Haskell code.

There is a wl-copy process running starting from when I press y, but nix-tree's timeout doesn't take effect: if I kill wl-copy or it exits because something else is copied to the clipboard, nix-tree will report that it timed out, but long after the specified timeout has expired.

What I don't understand is why it's waiting for wl-copy to complete at all: wl-copy forks itself to run in the background (to service any paste requests), but the main process exits almost immediately with a success exit code. I'd expect that nix-tree receives this success code, interprets that as a success, and continues to operate normally. Maybe we're using System.Process.Typed wrong?

@utdemir
Copy link
Owner

utdemir commented Dec 21, 2021

Very interesting. Thank you for delving in @lheckemann.

System.Timeout can only interrupt Haskell code.

This is good to know, but my mental model was that System.Process runs the process on a separate Haskell thread and communicates it via STM; so it should be interruptible as it's not a long-running FFI call.

Maybe we're using System.Process.Typed wrong?

Maybe. But we are not doing anything fancy, other than calling readProcess:

P.proc (toString cmd) (map toString args)
& P.setStdin (P.byteStringInput $ encodeUtf8 txt)
& P.readProcess
& timeout 1_000_000

But clearly there's something I'm missing in this picture, as I can not explain why it blocks.

So, I'll have a look at it later this weekend, and try to reproduce the issue (but do feel free to experiment more/fix if you're feel like it)

@utdemir
Copy link
Owner

utdemir commented Dec 25, 2021

@lheckemann I just checked, and it seems like grabbing stdout (and stderr) of the child process was causing the System.Timeout.timeout to not work. I made 27e7c2c which just inherits stdout and stderr, which fixed the timeout.

But I do not know whether it fixed the wl-copy issue. Can you have a look? Otherwise, I do not have a Wayland machine so I don't how I can debug it; but do let me know if you have an idea I should try out.

@bew
Copy link

bew commented Dec 26, 2021

Tested it on my side, on X11 using xclip (it was freezing for me as well), and now it doesn't freeze anymore 👍

@utdemir
Copy link
Owner

utdemir commented Jan 28, 2022

I'm tentatively marking this as done as per @bew's comment; @lheckemann please feel free to reopen it if the new version doesn't solve your issue!

@utdemir utdemir closed this as completed Jan 28, 2022
@lheckemann
Copy link
Author

Works wonderfully, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants