[libvirt] [PATCH] Fix error reporting when poll returns POLLHUP/POLLERR

Daniel P. Berrange posted 1 patch 7 years ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20170418160546.30666-1-berrange@redhat.com
src/rpc/virnetclient.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
[libvirt] [PATCH] Fix error reporting when poll returns POLLHUP/POLLERR
Posted by Daniel P. Berrange 7 years ago
In the RPC client event loop code, if poll() returns only a POLLHUP
or POLLERR status, then we end up reporting a bogus error message:

  error: failed to connect to the hypervisor
  error: An error occurred, but the cause is unknown

We do actually report an error, but we virNetClientMarkClose method
has already captured the error status before we report it, so the
real error gets thrown away. The key fix is to report the error
before calling virNetClientMarkClose(). In changing this, we also
split out reporting of POLLHUP vs POLLERR to make any future bugs
easier to diagnose.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 src/rpc/virnetclient.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
index 5174614..c959747 100644
--- a/src/rpc/virnetclient.c
+++ b/src/rpc/virnetclient.c
@@ -1743,10 +1743,16 @@ static int virNetClientIOEventLoop(virNetClientPtr client,
         if (error)
             goto error;
 
-        if (fds[0].revents & (POLLHUP | POLLERR)) {
+        if (fds[0].revents & POLLHUP) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("received hangup event on socket"));
             virNetClientMarkClose(client, VIR_CONNECT_CLOSE_REASON_EOF);
+            goto error;
+        }
+        if (fds[0].revents & POLLERR) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                           _("received hangup / error event on socket"));
+                           _("received error event on socket"));
+            virNetClientMarkClose(client, VIR_CONNECT_CLOSE_REASON_ERROR);
             goto error;
         }
     }
-- 
2.9.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] Fix error reporting when poll returns POLLHUP/POLLERR
Posted by John Ferlan 6 years, 12 months ago

On 04/18/2017 12:05 PM, Daniel P. Berrange wrote:
> In the RPC client event loop code, if poll() returns only a POLLHUP
> or POLLERR status, then we end up reporting a bogus error message:
> 
>   error: failed to connect to the hypervisor
>   error: An error occurred, but the cause is unknown
> 
> We do actually report an error, but we virNetClientMarkClose method
> has already captured the error status before we report it, so the
> real error gets thrown away. The key fix is to report the error
> before calling virNetClientMarkClose(). In changing this, we also
> split out reporting of POLLHUP vs POLLERR to make any future bugs
> easier to diagnose.
> 
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
>  src/rpc/virnetclient.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 

ACK

John

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list