<div dir="auto"><div><div dir="auto">Hi,</div><div dir="auto"><br></div><div dir="auto">I tried to fix this bug in a less radical way, but my patch unfortunately did not cover all the cases.</div><div dir="auto"><br></div><div dir="auto">I obtained some logs from James Harvey which make the situation clearer - it can be found here:</div><div dir="auto"><a href="https://termbin.com/40un">https://termbin.com/40un</a></div><div dir="auto">So I'll try to explain what's happening:</div><div dir="auto"><br></div><div dir="auto">James uses KDE which has a clipboard manager integrated in (klipper).</div><div dir="auto"><br></div><div dir="auto">(1) user copies something in the guest, grab is sent to the spice-gtk</div><div dir="auto">(2) clipboard manager immediately requests the data, data is retrieved from the vdagent</div><div dir="auto">(3) user pastes the copied data in guest, this causes a quick re-grab in the guest = a clipboard release message is sent to spice-gtk and it is immediately followed by a new grab</div><div dir="auto">(4) spice-gtk receives clipboard release, so it clears the clipboard</div><div dir="auto">(5) clipboard manager detects that the clipboard has no owner, so it grabs it itself, advertising the data it originally obtained from us in step (2) (this normally enables the user to paste the data even after the source app has been closed)</div><div dir="auto">(6) spice-gtk receives "owner-change" signal caused by the grab in step (5), requests clipboard targets and sends a grab to vdagent</div><div dir="auto">(7) spice-gtk finally receives the grab from step (3), so it sets the clipboard using gtk_clipboard_set_with_owner()</div><div dir="auto">(8) vdagent receives grab from step (6), so it too sets the clipboard using gtk_clipboard_set_with_owner()</div><div dir="auto"><br></div><div dir="auto">This is clearly a race. We ended up in a state where both spice-gtk and vdagent thinks the other component can provide the data, but in reality none of them can.</div><div dir="auto"><br></div><div dir="auto">(This does not happen always, as can be seen in the log, the first paste succeeds.)</div><div dir="auto"><br></div><div dir="auto">Given current spice protocol, I don't see a way to detect the race on either side, but I'd love to be wrong. So I'd update the commit log and comment in the code to explain the situation and then it's ack from me.</div><div dir="auto"><br></div><div dir="auto">Cheers,</div><div dir="auto">Jakub</div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jan 14, 2019, 1:34 PM Victor Toso <<a href="mailto:victortoso@redhat.com">victortoso@redhat.com</a> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Victor Toso <<a href="mailto:me@victortoso.com" target="_blank" rel="noreferrer">me@victortoso.com</a>><br>
<br>
On X11, the release-grab message might end up clearing the<br>
GtkClipboard which triggers the owner-changed callback having the<br>
event owner as NULL.<br>
<br>
We should not be calling gtk_clipboard_request_targets() in this<br>
situation as is prone to errors as the intention here is request<br>
clipboard information from changes made by client OS.<br>
<br>
The fix is to avoid any such request while spice client is holding the<br>
keyboard grab.<br>
<br>
Related: <a href="https://gitlab.freedesktop.org/spice/win32/vd_agent/issues/6" rel="noreferrer noreferrer" target="_blank">https://gitlab.freedesktop.org/spice/win32/vd_agent/issues/6</a><br>
Related: <a href="https://gitlab.freedesktop.org/spice/linux/vd_agent/issues/9" rel="noreferrer noreferrer" target="_blank">https://gitlab.freedesktop.org/spice/linux/vd_agent/issues/9</a><br>
Related: <a href="https://bugzilla.redhat.com/show_bug.cgi?id=1594876" rel="noreferrer noreferrer" target="_blank">https://bugzilla.redhat.com/show_bug.cgi?id=1594876</a><br>
<br>
Changed in v4:<br>
- Updated commit log<br>
<br>
Signed-off-by: Victor Toso <<a href="mailto:victortoso@redhat.com" target="_blank" rel="noreferrer">victortoso@redhat.com</a>><br>
Tested-by: James Harvey @jamespharvey20<br>
---<br>
src/spice-gtk-session.c | 13 +++++++++++++<br>
1 file changed, 13 insertions(+)<br>
<br>
diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c<br>
index abce43f..20df70d 100644<br>
--- a/src/spice-gtk-session.c<br>
+++ b/src/spice-gtk-session.c<br>
@@ -674,6 +674,19 @@ static void clipboard_owner_change(GtkClipboard *clipboard,<br>
return;<br>
}<br>
<br>
+#ifdef GDK_WINDOWING_X11<br>
+ /* In X11, while holding the keyboard-grab we are not interested in this<br>
+ * event as it either came by grab or release messages from agent. */<br>
+ if (GDK_IS_X11_DISPLAY(gdk_display_get_default()) &&<br>
+ spice_gtk_session_get_keyboard_has_focus(self)) {<br>
+ SPICE_DEBUG("clipboard: owner-changed event: not requesting client's target "<br>
+ "while holding focus");<br>
+ return;<br>
+ }<br>
+#endif<br>
+ SPICE_DEBUG("clipboard: owner-changed event: has-focus=%d",<br>
+ spice_gtk_session_get_keyboard_has_focus(self));<br>
+<br>
s->clipboard_by_guest[selection] = FALSE;<br>
s->clip_hasdata[selection] = TRUE;<br>
if (s->auto_clipboard_enable && !read_only(self))<br>
-- <br>
2.20.1<br>
<br>
</blockquote></div></div></div>