Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1713548

Summary: remote-viewer can not be closed when connection with guest is lost
Product: Red Hat Enterprise Linux 7 Reporter: yafu <yafu>
Component: virt-viewerAssignee: Kevin Pouget <kpouget>
Status: CLOSED CURRENTRELEASE QA Contact: Virtualization Bugs <virt-bugs>
Severity: low Docs Contact:
Priority: low    
Version: 7.7CC: berrange, dblechte, jjongsma, juzhou, kpouget, tzheng, victortoso, xiaodwan
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2019-11-05 13:54:26 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
virt-viewer log
none
Latest virt-viewer version testing log none

Description yafu 2019-05-24 04:56:15 UTC
Created attachment 1572783 [details]
virt-viewer log

Description:
remote-viewer can not be closed when close remote-viewer which lost connection with guest

Version:
virt-viewer-5.0-14.el7.x86_64
spice-gtk3-0.35-4.el7.x86_64

Reproduce:
100%

Steps to reproducible:
1.Connect a guest in the third host with remote-viewer:
#remote-viewer spice://10.66.4.143:5900

2.Do migration:
#virsh migrate vm1 qemu+ssh://10.66.70.118/system --live --verbose

3.After migration completed, remote-viewer lost connection with the guest since not set target hostname in the third host;

4.Close remote-viewer opened in step 1.

5.# pgrep remote-viewer
11851

Actual results:
The process still exists and the windows can not be closed.

Expected results:
remote-viewer windows can be closed and the process exit.


Additional info:
1.Can not be reproduced with virt-viewer-5.0-13.el7.x86_64.

Comment 2 Victor Toso 2019-05-24 09:45:37 UTC
> 3.After migration completed, remote-viewer lost connection with the guest since not set target hostname in the third host;

Interesting.

> 1.Can not be reproduced with virt-viewer-5.0-13.el7.x86_64.

Difference between -13 and -14 build is the fix for bug 1505809
Let's see if Jonathon has time for it, otherwise I'll take a look later.

Comment 3 Kevin Pouget 2019-06-13 07:26:14 UTC
I may have stumbled on a related issue while playing with Qemu/virsh: in some cases where Qemu quitted unexpectedly, the virt-viewer would lost connection to the VM, but the virt-viewer window refused to quit.

> static void virt_viewer_app_quit(VirtViewerApp *self)
> {
>     ...
>
>     if (priv->session) {
>         virt_viewer_session_close(VIRT_VIEWER_SESSION(priv->session));
>         if (priv->connected) {
>             priv->quitting = TRUE;
>             return;
>         }
>     }
>
>     g_application_quit(G_APPLICATION(self));
> }

always sets the quitting flag, but nothing else happens.

This means that the disconnected/cancelled functions are never called *after* the quit request:

> static void
> virt_viewer_app_disconnected(VirtViewerSession *session G_GNUC_UNUSED, const gchar *msg, VirtViewerApp *self)
> {
>     ...
>     if (priv->quitting)
>         g_application_quit(G_APPLICATION(self));
>     ...
> }
>
> static void virt_viewer_app_cancelled(VirtViewerSession *session,
>                                       VirtViewerApp *self)
> {
>     VirtViewerAppPrivate *priv = self->priv;
>     priv->cancelled = TRUE;
>     virt_viewer_app_disconnected(session, NULL, self);
> }


so one way to solve this problem is to force-quit if the `quitting` flag has already been set (= click on 'quit' twice):

diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index da8cfa9..47b1a46 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -298,7 +298,7 @@ virt_viewer_app_quit(VirtViewerApp *self)
 
     if (priv->session) {
         virt_viewer_session_close(VIRT_VIEWER_SESSION(priv->session));
-        if (priv->connected) {
+        if (priv->connected && !priv->quitting) {
             priv->quitting = TRUE;
             return;
         }

another way could be to check if the `cancelled` flag has been set earlier (hopefully yes but I didn't check yet), and quit if yes:

diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index da8cfa9..47b1a46 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -298,7 +298,7 @@ virt_viewer_app_quit(VirtViewerApp *self)
 
     if (priv->session) {
         virt_viewer_session_close(VIRT_VIEWER_SESSION(priv->session));
-        if (priv->connected) {
+        if (priv->connected && !priv->cancelled) {
             priv->quitting = TRUE;
             return;
         }

Comment 4 Kevin Pouget 2019-10-31 11:22:28 UTC
I managed to reproduce once the buggy behavior (cannot close the remote-viewer window) with the HEAD I used at the time of comment #3 [0] by manually triggering a segfault in Qemu, but I cannot reproduce it again ...

My debugging investigations lead to the conclusion that if spice-gtk doesn't send the DISCONNECTED signal [1] for any reason, then the viewer cannot be closed.

The patch [2] allows a 'force-close' if the user requests twice to close the app:                                                                                       
                                                                                               
1. The first time, `virt_viewer_session_close(VIRT_VIEWER_SESSION(priv->session))` is called,
which should trigger the DISCONNECTED signal and close the app. If this fails,
2. The second time, the application is closed, no matter the internal state.


0: https://pagure.io/virt-viewer/c/898f972
1: https://gitlab.freedesktop.org/spice/spice-gtk/blob/0c52ce8937c849d8ae32ade1f22ce3a48c56c732/src/spice-session.c#L2322
2: https://www.redhat.com/archives/virt-tools-list/2019-October/msg00022.html

Comment 5 zhoujunqin 2019-11-01 05:22:10 UTC
Reproduce with packages:
libvirt-4.5.0-23.el7_7.3.x86_64
virt-viewer-5.0-15.el7.x86_64
qemu-kvm-rhev-2.12.0-33.el7_7.4.x86_64
spice-gtk3-0.35-4.el7.x86_64

Steps:
1. Prepare migration env on HOST1 and HOST2

2. Start a vm with spice graphic on src host(HOST1)
...
    <graphics type='spice' port='5900' autoport='yes' listen='0.0.0.0'>
      <listen type='address' address='0.0.0.0'/>
      <image compression='off'/>
    </graphics>

3.Connect vm on the third machine($HOST3) with remote-viewer:
$ remote-viewer spice://$HOST3:5900

4.Do migration between HOST1 and HOST2
#virsh migrate vm1 qemu+ssh://$HOST2/system --live --verbose

5.After migration completed, remote-viewer lost connection with the guest since not set target hostname on HOST3

$ cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

6.Close remote-viewer opened in step 3.

Result: The remote-viewer windows can not be closed.
And the process is still existing.
$ pgrep remote-viewer
27293


And Kevin,
How about your plan to make the new build of virt-viewer, I hope it asap then we can have enough time to verify bug and do related functional testing.

BR,
juzhou.

Comment 6 zhoujunqin 2019-11-01 06:20:20 UTC
Hi Kevin Pouget,
Comment 5 is tested based on rhel7.7 released version.

Then I tested with latest rhel7.8 packages, i can not reproduce bug issue.

Packages:

libvirt-4.5.0-28.el7.x86_64
virt-viewer-5.0-17.el7.x86_64
qemu-kvm-rhev-2.12.0-38.el7.x86_64
spice-gtk3-0.35-5.el7.x86_64

Steps are same with Comment 5:
After step 5, remote-viewer windows closed successfully after migration finished and the process exited.

I will attach the debug log: 5.0-17.log

Comment 7 zhoujunqin 2019-11-01 06:21:32 UTC
Created attachment 1631349 [details]
Latest virt-viewer version testing log

Comment 8 Kevin Pouget 2019-11-04 17:13:59 UTC
the patch I proposed (https://bugzilla.redhat.com/show_bug.cgi?id=1713548#c4) was rejected upstream, so I revert the bug status to NEW.

Comment 9 zhoujunqin 2019-11-05 02:39:24 UTC
(In reply to Kevin Pouget from comment #8)
> the patch I proposed
> (https://bugzilla.redhat.com/show_bug.cgi?id=1713548#c4) was rejected
> upstream, so I revert the bug status to NEW.

Hi Kevin,
Thanks for your quick feedback, and as you said in email, we'll close this bug as "CURRENTRELEASE" if Victor agree.

BR,
juzhou.

Comment 10 Victor Toso 2019-11-05 13:54:26 UTC
As per comment #6 and further discussions, closing this one.