Bug 8427 - Some apps in session can hang when copying images in client side
Summary: Some apps in session can hang when copying images in client side
Status: NEW
Alias: None
Product: ThinLinc
Classification: Unclassified
Component: Client (show other bugs)
Version: trunk
Hardware: PC Unknown
: P2 Normal
Target Milestone: LowPrio
Assignee: Bugzilla mail exporter
URL:
Keywords: upstream
Depends on:
Blocks:
 
Reported: 2024-10-01 09:29 CEST by Samuel Mannehed
Modified: 2024-10-01 14:57 CEST (History)
1 user (show)

See Also:
Acceptance Criteria:


Attachments

Description Samuel Mannehed cendio 2024-10-01 09:29:10 CEST
Steps to reproduce:

1. Connect using the ThinLinc client on Windows
2. In the session, open the app QGIS and open the default project "Bee Farming"
3. On the Windows side (client-side), copy a image
4. Notice that the QGIS app freezes, (the rest of the ThinLinc session is functional)
Comment 2 William Sjöblom cendio 2024-10-01 11:52:48 CEST
Note: The "default project" mentioned above is not part of the QGIS. It was downloaded separately from here https://docs.qfield.org/get-started/sample-projects/
Comment 3 Samuel Mannehed cendio 2024-10-01 12:47:50 CEST
The following log messages can be seen when reproducing according to Comment 0:

vncviewer:

> Tue Oct 01 11:30:04 2024
>  Viewport:    Local clipboard changed whilst not focused, will notify server
>              later
> 
> Tue Oct 01 11:30:06 2024
>  Viewport:    Focus regained after local clipboard change, notifying server

Xvnc:

> Tue Oct  1 11:30:04 2024
>  Selection:   Remote clipboard lost, removing local ownership
> 
> Tue Oct  1 11:30:06 2024
>  Selection:   Remote clipboard announced, grabbing local ownership
>  Selection:   Grabbed PRIMARY selection
>  Selection:   Grabbed CLIPBOARD selection
>  Selection:   Selection request for PRIMARY (type TARGETS)
>  Selection:   Selection request for PRIMARY (type UTF8_STRING)
>  Selection:   Requesting clipboard data from client
> 
> Tue Oct  1 11:30:11 2024
>  Selection:   Selection request for PRIMARY (type UTF8_STRING)
>  Selection:   Requesting clipboard data from client
> 
> Tue Oct  1 11:30:16 2024
>  Selection:   Selection request for PRIMARY (type UTF8_STRING)
>  Selection:   Requesting clipboard data from client
> 
> Tue Oct  1 11:30:21 2024
>  Selection:   Selection request for CLIPBOARD (type TARGETS)

After some digging, I found that FLTK has support for reading either plaintext or images from the clipboard [1]. The process is like this:

 1. We use Fl::add_clipboard_notify() to get notified of clipboard changes on
    the client OS.
 2. The handler for this event in vncviewer, Viewport::handleClipboardChange(),
    will announce to the VNC server — that clipboard data is available.
 3. When the server gets this notification, it will, in turn, announce to 
    applications in the session, that clipboard is available.
 4. The application asks for clipboard in this case, so the VNC server will
    send back a request for a clipboard sync to the viewer, via
    vncRequestClipboard() in vncSelection.c.
 5. The viewer receives the clipboardRequest and calls handleClipboardRequest()
    from CMsgReader::readExtendedClipboard().
 6. A few layers in, Viewport::handleClipboardRequest() calls Fl::paste() which 
    emits the FL_PASTE event.
 7. In the handling of this event, in Viewport::handle(), there is some
    filtering that likely only let plain text clipboard data get sent.

The problem for the QGIS application seems to occur when it has been notified by the VNC server that clipboard is available, and then doesn't get anything after asking for it.

[1]: https://www.fltk.org/doc-1.3/group__fl__clipboard.html#gaa01ff0cf95384f8255fa80edcbe1432d
Comment 4 Samuel Mannehed cendio 2024-10-01 13:45:55 CEST
Simply preventing the viewer from sending the "announceClipboard" message to the server seems to help in this case. I fixed it in upstream TigerVNC:

https://github.com/TigerVNC/tigervnc/pull/1840

Note You need to log in before you can comment on or make changes to this bug.