xsel icon indicating copy to clipboard operation
xsel copied to clipboard

xsel silently fails to set selection to file contents if over ~4000 bytes

Open skierpage opened this issue 5 years ago • 2 comments

xsel version 1.2.0 (Fedora package xsel-1.2.0-24.fc30.src.rpm) Fedora 30 KDE Spin X.Org X Server 1.20.5. (xorg-x11-server 1.20.5-4.fc30).

After writing all the below this sounds like closed bugs #13 and #14, but I think I'm running latest version 1.20 ??!

I've used xsel -b for years, thanks! Today I tried to set the clipboard selection to the contents of a 9 kB file with xsel -b < MYFILE and after 10 minutes of WTF I realized the command was failing and setting the clipboard contents to empty, even though its exit status $? is 0. When it fails it appends xsel: BadWindow (invalid Window parameter): Resource temporarily unavailable to ~/.xsel.log.

I reduced and increased the file size until I determined that xsel -b < SOMEFILE succeeds with a 4075-byte file and fails with 4076 bytes... but now 4075 is failing too! So the limit varies. I can use Ctrl-C in GUI apps to set the clipboard selection to much bigger files.

I ran strace on the failure vs/ successful xsel of another file, and the contents are essentially the same, then I realized there's a child process ;-) ; with -ff the child process gets some errors from recvmsg(3, {msg_namelen=0}, 0) = -1 EAGAIN (Resource temporarily unavailable) but seems to keep going and writes bits of the file until it opens /usr/share/X11/XErrorDB and reports errors. I can upload the strace if it will help.

I'll file a separate bug that when the child process fails with exit_group(1), the error isn't reported to the parent.

skierpage avatar Sep 10 '19 23:09 skierpage

I built latest xsel from source and still have this problem. Sometimes the child process that xsel forks times out with BadWindow and sometimes doesn't. When I first ran xsel -b --nodetach < MY_4k_FILE, it took many seconds before printing out

/tmp/xsel_build/bin/xsel: BadWindow (invalid Window parameter): Resource temporarily unavailable

and exit, but if I repeat the command it fails quickly with the same error... and then other times it works, waiting for someone to request the selection and providing it correctly.

skierpage avatar Sep 11 '19 07:09 skierpage

Maybe this commit from fork will fix it? On input, dont exit parent (returning to invoker) until either select… · mckellyln/xsel@b7d8442⠀ https://github.com/mckellyln/xsel/commit/b7d8442d9f661550ef78a4f1bd164bf7304f70db

However, neovim simply started preferring xclip due to xsel codebase being neglected... nvim xsel not working properly? · Issue #5853 · neovim/neovim https://github.com/neovim/neovim/issues/5853

amerlyq avatar Nov 29 '20 10:11 amerlyq