qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com>,
	"Daniel P . Berrange" <berrange@redhat.com>
Subject: [Qemu-devel] [PULL 2/7] io/channel-websock: handle continuous reads without any data
Date: Thu, 15 Feb 2018 17:50:39 +0000	[thread overview]
Message-ID: <20180215175044.8159-3-berrange@redhat.com> (raw)
In-Reply-To: <20180215175044.8159-1-berrange@redhat.com>

From: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com>

According to the current implementation of websocket protocol in QEMU,
qio_channel_websock_handshake_io tries to read handshake from the
channel to start communication over socket. But this approach
doesn't cover scenario when socket was closed while handshaking.
Therefore, if G_IO_IN is caught and qio_channel_read returns zero,
error has to be set and connection has to be done.

Such behaviour causes 100% CPU load in main QEMU loop, because main loop
poll continues to receive and handle G_IO_IN events from websocket.

Step to reproduce 100% CPU load:
1) start qemu with the simplest configuration
$ qemu -vnc [::1]:1,websocket=7500
2) open any vnc listener (which doesn't follow websocket
protocol)
$ vncviewer :7500
3) kill listener
4) qemu main thread eats 100% CPU

Signed-off-by: Edgar Kaziakhmedov <edgar.kaziakhmedov@virtuozzo.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 io/channel-websock.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/io/channel-websock.c b/io/channel-websock.c
index 7fd6bb68ba..ec48a305f0 100644
--- a/io/channel-websock.c
+++ b/io/channel-websock.c
@@ -499,9 +499,12 @@ static int qio_channel_websock_handshake_read(QIOChannelWebsock *ioc,
             error_setg(errp,
                        "End of headers not found in first 4096 bytes");
             return 1;
-        } else {
-            return 0;
+        } else if (ret == 0) {
+            error_setg(errp,
+                       "End of headers not found before connection closed");
+            return -1;
         }
+        return 0;
     }
     *handshake_end = '\0';
 
-- 
2.14.3

  parent reply	other threads:[~2018-02-15 17:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-15 17:50 [Qemu-devel] [PULL 0/7] Qio next patches Daniel P. Berrangé
2018-02-15 17:50 ` [Qemu-devel] [PULL 1/7] io: fix QIONetListener memory leak Daniel P. Berrangé
2018-02-15 17:50 ` Daniel P. Berrangé [this message]
2018-02-15 17:50 ` [Qemu-devel] [PULL 3/7] io: Fix QIOChannelFile when creating and opening read-write Daniel P. Berrangé
2018-02-15 17:50 ` [Qemu-devel] [PULL 4/7] io: Don't call close multiple times in QIOChannelFile Daniel P. Berrangé
2018-02-15 17:50 ` [Qemu-devel] [PULL 5/7] io: Add /dev/fdset/ support to QIOChannelFile Daniel P. Berrangé
2018-02-15 17:50 ` [Qemu-devel] [PULL 6/7] io/channel-command: Do not kill the child process after closing the pipe Daniel P. Berrangé
2018-02-15 17:50 ` [Qemu-devel] [PULL 7/7] allow to build with older sed Daniel P. Berrangé
2018-02-15 19:43 ` [Qemu-devel] [PULL 0/7] Qio next patches Peter Maydell
2018-02-16  8:52   ` Daniel P. Berrangé
2018-02-16 12:51 ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180215175044.8159-3-berrange@redhat.com \
    --to=berrange@redhat.com \
    --cc=edgar.kaziakhmedov@virtuozzo.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).