From patchwork Thu Dec 28 09:36:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 853384 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3z6l3p2zJhz9s72 for ; Thu, 28 Dec 2017 20:36:53 +1100 (AEDT) Received: from localhost ([::1]:43731 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUUcM-0005oX-KS for incoming@patchwork.ozlabs.org; Thu, 28 Dec 2017 04:36:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39269) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUUc0-0005o9-6r for qemu-devel@nongnu.org; Thu, 28 Dec 2017 04:36:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eUUbv-0004gb-5u for qemu-devel@nongnu.org; Thu, 28 Dec 2017 04:36:28 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:37458 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eUUbu-0004VP-Q2 for qemu-devel@nongnu.org; Thu, 28 Dec 2017 04:36:23 -0500 Received: from iris.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id vBRK6XW9010662; Wed, 27 Dec 2017 23:06:33 +0300 (MSK) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Date: Thu, 28 Dec 2017 12:36:18 +0300 Message-Id: <1514453778-5363-1-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 1/1] io/channel-websock: handle continuous reads without any data X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Denis V . Lunev" , Edgar Kaziakhmedov Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Edgar Kaziakhmedov 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 tcp socket. But this subroutine doesn't cover scenario when socket was closed while handshaking. Therefore, if G_IO_IN is caught and qio_channel_websock_handshake_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: - 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 usage Signed-off-by: Edgar Kaziakhmedov Signed-off-by: Denis V. Lunev CC: Daniel P. Berrange --- io/channel-websock.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/io/channel-websock.c b/io/channel-websock.c index 87ebdeb..71f046a 100644 --- a/io/channel-websock.c +++ b/io/channel-websock.c @@ -581,9 +581,11 @@ static gboolean qio_channel_websock_handshake_io(QIOChannel *ioc, return FALSE; } if (ret == 0) { - trace_qio_channel_websock_handshake_pending(ioc, G_IO_IN); - /* need more data still */ - return TRUE; + /* If G_IN_IO happened and there is no data to read, close connection */ + error_setg(&err, "connection was closed"); + qio_task_set_error(task, err); + qio_task_complete(task); + return FALSE; } if (err) {