gpbs: timeout INCR transfer receive to stop pasteboard hangs - #231
gpbs: timeout INCR transfer receive to stop pasteboard hangs#231probonopd wants to merge 3 commits into
Conversation
gpbs blocks forever in the X selection incremental (INCR) receive loop when the selection owner dies or stalls mid-transfer, making the whole pasteboard unresponsive and forcing gpbs to be killed. Wait on the X connection descriptor with a 5s deadline before each INCR chunk; on timeout abandon the transfer and discard the partial data instead of blocking on XNextEvent indefinitely.
The error handler is referenced in +initializePasteboard before its definition; GCC (as used on CI) rejects the implicit declaration. Declare it explicitly so the build succeeds everywhere.
|
I don't know how often we want to handle multiple pasteboard requests at about the same time, but if it is a big issue then I think the solution would be to rewrite this to be asynchronous (or multithreaded with coordination on the X server comms) and handle them all at once. However, this timeout seems a good simple option. |
|
What timeout would you suggest? |
|
My best recollection is that Gimp was taking what seemed like a very long time, but not so long that we gave up ... more than 5, but less than 30. My intuition is that Gimp is an extreme case. Most apps ought to be fast enough because the data to be pasted is small, and the only thing larger than images would be things like audio/video where apps are built to stream and either cut/paste makes no sense or format conversion would be done while streaming (so the app would quickly send chunks of data rather than converting an entire video in one operation. So I think 30 seconds would be plenty long enough, and we might want it shorter than that if we want to try to avoid giving the impression that things gave hung. |
Allow for big images from Gimp not to time out
|
Updated to 20. |
|
@rfm yes indeed, I remember testing very long times. I also wonder what happens if there is a network in the middle, if that slows the whole timeout or only affects actual transfer times. @probonopd I did a lot of copy&paste testing also with very big file to test multiple chunks and never got crashes, how did you get to that? |
|
Had observed flaky copy&paste on the Gershwin Desktop, so I had AI analyze the code and suggest probable causes, then did a lot of manual testing. Here is my understanding of the situation: The problem is that clipboard data can be transferred in multiple pieces when using X11's This change avoids that by checking the X11 connection with This seems to be working for me constantly. I have been using it on my daily driver machine (Devuan) for a while now. |
gpbs blocks forever in the X selection incremental (INCR) receive loop when the selection owner dies or stalls mid-transfer, making the whole pasteboard unresponsive and forcing gpbs to be killed.
Fix: wait on the X connection descriptor with a 5s deadline before each INCR chunk; on timeout abandon the transfer and discard the partial data instead of blocking on XNextEvent indefinitely.
Verified: a stalling clipboard owner now causes a nil result after exactly 5s instead of a permanent hang, and gpbs serves subsequent pasteboard requests normally.