From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77289C4338F for ; Wed, 18 Aug 2021 20:24:31 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E62A360ED3 for ; Wed, 18 Aug 2021 20:24:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E62A360ED3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=nongnu.org Received: from localhost ([::1]:52052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mGS6w-0000Gv-0O for qemu-devel@archiver.kernel.org; Wed, 18 Aug 2021 16:24:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60856) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mGRMo-0004DH-C7 for qemu-devel@nongnu.org; Wed, 18 Aug 2021 15:36:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26133) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mGRMj-0003U2-Cw for qemu-devel@nongnu.org; Wed, 18 Aug 2021 15:36:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629315403; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MtSRlnhi3JtiTb06IZCub2AI5WRVpz899kqCg84XIpo=; b=FDoOJrdghYeD5C1odhx+I4AX+APfy+4iNpiju5ZtPDJveUzW+DIXkSHkCXDxa/dVOsKd0S ZpnLFHItB154W1Bb/CgaNBOhqPVWs9JU5zmlR1MQoJPBZPUncNwUev8ez8dmyy8EKo0KR5 Ei7T+R3KhYZBK4XWGgC7k59Xxjg1P8E= Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-133-U8SSHaZBONOwrnOks2C1MQ-1; Wed, 18 Aug 2021 15:36:40 -0400 X-MC-Unique: U8SSHaZBONOwrnOks2C1MQ-1 Received: by mail-oi1-f199.google.com with SMTP id e17-20020a0568081491b02901f566a77bb8so1490442oiw.7 for ; Wed, 18 Aug 2021 12:36:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MtSRlnhi3JtiTb06IZCub2AI5WRVpz899kqCg84XIpo=; b=HGhRjZliuJA+xUR4ocaNUU0Xdc6520uuZ0Oo7Z55ldmbF2geM+sBx/XiqiUnBRhD9H 3auBg34RUxikh4PRCwQKeQvLrlaP2ae8DqLA1kUuD0Nnf1u17g/1fkW2/juEyM9+ZaXk 9v0Ys7AbCPiuY5CHnlxMiMywxRYHyoOBcipDD4ATkrWjPpzgdmkcfFoIODUOyMu0wmGU Bz9m2N5C7KgWTp6+K/CxnDyZQdjZnfRiRbz4hlsh0hE/lQIY9/cAxyGjTUIt7dDOMqaa Baa9ufmUngOQy/d/v8vrrRa5kg8BO32eynwC07kC4kYOhTBal1jAFU0mUdhMmLdNSy72 5S6g== X-Gm-Message-State: AOAM530DiugCeVnNELOuLueDPTCBaTQhMcTnAD8RwAz44cZjVecOrw7F A6XYa5FRiz7l4sNselEt0GKDUYPFOMiEGAHUr0Hf75kOHgipv0vzH4Swpp7NuQ6mXnH5c6rFVoU hpeASNtNlQTh/TEqRH+lzf6/i+9XfyAw= X-Received: by 2002:a05:6808:1906:: with SMTP id bf6mr8219914oib.52.1629315398742; Wed, 18 Aug 2021 12:36:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqiQq3umqcq3jZ+E8Gze1QoeJWlzp6c3tuYtN0e+nlY89SYPJf5CvydpMIBeKNxVtPvO7ZyJFSt1Tx9wNuSMg= X-Received: by 2002:a05:6808:1906:: with SMTP id bf6mr8219893oib.52.1629315398535; Wed, 18 Aug 2021 12:36:38 -0700 (PDT) MIME-Version: 1.0 References: <20210730201846.5147-1-niteesh.gs@gmail.com> <20210730201846.5147-10-niteesh.gs@gmail.com> In-Reply-To: From: John Snow Date: Wed, 18 Aug 2021 15:36:27 -0400 Message-ID: Subject: Re: [PATCH v3 09/13] python/aqmp-tui: Add QMP connection manager To: "Niteesh G. S." Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: multipart/alternative; boundary="0000000000008e9cd705c9da8db8" Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.7, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Kashyap Chamarthy , Markus Armbruster , Wainer Moschetta , qemu-devel , Stefan Hajnoczi , Cleber Rosa , Eric Blake Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --0000000000008e9cd705c9da8db8 Content-Type: text/plain; charset="UTF-8" On Tue, Aug 17, 2021 at 3:07 PM Niteesh G. S. wrote: > > > On Tue, Aug 17, 2021 at 10:21 AM John Snow wrote: > >> >> >> On Fri, Jul 30, 2021 at 4:19 PM G S Niteesh Babu >> wrote: >> >> [...] > >> >>> + >>> + >>> class App(QMPClient): >>> - def __init__(self, address: Union[str, Tuple[str, int]]) -> None: >>> + def __init__(self, address: Union[str, Tuple[str, int]], >>> num_retries: int, >>> + retry_delay: Optional[int]) -> None: >>> urwid.register_signal(type(self), UPDATE_MSG) >>> self.window = Window(self) >>> self.address = address >>> self.aloop: Optional[Any] = None # FIXME: Use more concrete >>> type. >>> + self.num_retries = num_retries >>> + self.retry_delay = retry_delay >>> + self.retry: bool = False >>> + self.disconnecting: bool = False >>> >> >> Why is this one needed again ? ... >> > > A race condition occurs in protocol.py line 597 > The reason behind this is there are two disconnect calls initiated. The > first one via kill_app > and the second one via manage_connection when the state is set to > disconnecting by the first call. > One of the calls set's the state to IDLE(protocol.py:584) after it has > finished disconnecting, meanwhile > the second call is somehow in the process of disconnecting and assert the > state to be in DISCONNECTING > in protocol.py:597, which it is not since it has been set to IDLE by the > first call. > > If I don't gaurd against the second call I get the following exception > > ------------------------------------------------------------------------------------------ > Traceback (most recent call last): > File "/home/niteesh/development/qemu/python/.venv/bin/aqmp-tui", line > 33, in > sys.exit(load_entry_point('qemu', 'console_scripts', 'aqmp-tui')()) > File "/home/niteesh/development/qemu/python/qemu/aqmp/aqmp_tui.py", line > 695, in main > app.run(args.asyncio_debug) > File "/home/niteesh/development/qemu/python/qemu/aqmp/aqmp_tui.py", line > 444, in run > raise err > File "/home/niteesh/development/qemu/python/qemu/aqmp/aqmp_tui.py", line > 441, in run > main_loop.run() > File > "/home/niteesh/development/qemu/python/.venv/lib/python3.6/site-packages/urwid/main_loop.py", > line 287, in run > self._run() > File > "/home/niteesh/development/qemu/python/.venv/lib/python3.6/site-packages/urwid/main_loop.py", > line 385, in _run > self.event_loop.run() > File > "/home/niteesh/development/qemu/python/.venv/lib/python3.6/site-packages/urwid/main_loop.py", > line 1494, in run > reraise(*exc_info) > File > "/home/niteesh/development/qemu/python/.venv/lib/python3.6/site-packages/urwid/compat.py", > line 58, in reraise > raise value > File "/home/niteesh/development/qemu/python/qemu/aqmp/aqmp_tui.py", line > 391, in manage_connection > await self.disconnect() > File "/home/niteesh/development/qemu/python/qemu/aqmp/aqmp_tui.py", line > 312, in disconnect > raise err > File "/home/niteesh/development/qemu/python/qemu/aqmp/aqmp_tui.py", line > 300, in disconnect > await super().disconnect() > File "/home/niteesh/development/qemu/python/qemu/aqmp/protocol.py", line > 302, in disconnect > await self._wait_disconnect() > File "/home/niteesh/development/qemu/python/qemu/aqmp/protocol.py", line > 583, in _wait_disconnect > self._cleanup() > File "/home/niteesh/development/qemu/python/qemu/aqmp/qmp_client.py", > line 331, in _cleanup > super()._cleanup() > File "/home/niteesh/development/qemu/python/qemu/aqmp/protocol.py", line > 597, in _cleanup > assert self.runstate == Runstate.DISCONNECTING > AssertionError > > ------------------------------------------------------------------------------------------- > Hm, OK. I'm not sure if this is a bug on my part or not yet, I'll investigate. > def add_to_history(self, msg: str, level: Optional[str] = None) -> >>> None: >>> @@ -119,7 +132,7 @@ def _cb_inbound(self, msg: Message) -> Message: >>> LOGGER.info('Error server disconnected before reply') >>> urwid.emit_signal(self, UPDATE_MSG, >>> '{"error": "Server disconnected before >>> reply"}') >>> - self._set_status("Server disconnected") >>> + await self.disconnect() >>> except Exception as err: >>> LOGGER.error('Exception from _send_to_server: %s', str(err)) >>> raise err >>> @@ -136,15 +149,29 @@ def kill_app(self) -> None: >>> create_task(self._kill_app()) >> >> Is this required? I would have hoped that after calling disconnect that >> the state would have again changed to IDLE and you wouldn't need this >> clause here. >> > After you mentioned it I too felt it was redundant. But on removing it the > whole app freezes when trying to exit. > I logged the state after the call to disconnect, instead of being in the > IDLE state, it is still in DISCONNECTING state. > I suspect this results in the constant infinite looping which doesn't give > other coroutines a chance to run and blocks > the event loop thus resulting in the freezing of the app. But I am not > sure why the state isn't changing to IDLE. > Hmm ... That may well be a bug in AQMP then. I will investigate. --0000000000008e9cd705c9da8db8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Tue, Aug 17, 2021 at 3:07 PM Nitee= sh G. S. <niteesh.gs@gmail.com> wrote:


<= br>

On Fri, Jul 30, 2021 at 4:19 PM G S Niteesh Babu <niteesh.gs@gmail.com> wrote:<= br>


[...]
=C2=A0
=C2=A0
+
+
=C2=A0class App(QMPClient):
-=C2=A0 =C2=A0 def __init__(self, address: Union[str, Tuple[str, int]]) -&g= t; None:
+=C2=A0 =C2=A0 def __init__(self, address: Union[str, Tuple[str, int]], num= _retries: int,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0retry_delay:= Optional[int]) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0urwid.register_signal(type(self), UPDATE_= MSG)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.window =3D Window(self)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.address =3D address
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.aloop: Optional[Any] =3D None=C2=A0 = # FIXME: Use more concrete type.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.num_retries =3D num_retries
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.retry_delay =3D retry_delay
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.retry: bool =3D False
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.disconnecting: bool =3D False

Why is this one needed again ? ...
=
=C2=A0
A race condition = occurs in protocol.py line 597
The reas= on behind this is there are two disconnect calls initiated. The first one v= ia kill_app
and the second one via mana= ge_connection when the state is set to disconnecting by the first call.
One of the calls set's the state to ID= LE(protocol.py:584) after it has finished disconnecting, meanwhile
the second call is somehow in the process of di= sconnecting and assert the state to be in DISCONNECTING
in protocol.py:597, which it is not since it has been set = to IDLE by the first call.

If I don't gaurd against the second = call I get the following exception
----= ---------------------------------------------------------------------------= -----------
Traceback (most recent call= last):
=C2=A0 File "/home/niteesh/development/qemu/python/.venv/bi= n/aqmp-tui", line 33, in <module>
=C2=A0 =C2=A0 sys.exit(load= _entry_point('qemu', 'console_scripts', 'aqmp-tui')= ())
=C2=A0 File "/home/niteesh/development/qemu/python/qemu/aqmp/aq= mp_tui.py", line 695, in main
=C2=A0 =C2=A0 app.run(args.asyncio_de= bug)
=C2=A0 File "/home/niteesh/development/qemu/python/qemu/aqmp/a= qmp_tui.py", line 444, in run
=C2=A0 =C2=A0 raise err
=C2=A0 Fil= e "/home/niteesh/development/qemu/python/qemu/aqmp/aqmp_tui.py", = line 441, in run
=C2=A0 =C2=A0 main_loop.run()
=C2=A0 File "/hom= e/niteesh/development/qemu/python/.venv/lib/python3.6/site-packages/urwid/m= ain_loop.py", line 287, in run
=C2=A0 =C2=A0 self._run()
=C2=A0 = File "/home/niteesh/development/qemu/python/.venv/lib/python3.6/site-p= ackages/urwid/main_loop.py", line 385, in _run
=C2=A0 =C2=A0 self.e= vent_loop.run()
=C2=A0 File "/home/niteesh/development/qemu/python/= .venv/lib/python3.6/site-packages/urwid/main_loop.py", line 1494, in r= un
=C2=A0 =C2=A0 reraise(*exc_info)
=C2=A0 File "/home/niteesh/d= evelopment/qemu/python/.venv/lib/python3.6/site-packages/urwid/compat.py&qu= ot;, line 58, in reraise
=C2=A0 =C2=A0 raise value
=C2=A0 File "= /home/niteesh/development/qemu/python/qemu/aqmp/aqmp_tui.py", line 391= , in manage_connection
=C2=A0 =C2=A0 await self.disconnect()
=C2=A0 F= ile "/home/niteesh/development/qemu/python/qemu/aqmp/aqmp_tui.py"= , line 312, in disconnect
=C2=A0 =C2=A0 raise err
=C2=A0 File "/= home/niteesh/development/qemu/python/qemu/aqmp/aqmp_tui.py", line 300,= in disconnect
=C2=A0 =C2=A0 await super().disconnect()
=C2=A0 File &= quot;/home/niteesh/development/qemu/python/qemu/aqmp/protocol.py", lin= e 302, in disconnect
=C2=A0 =C2=A0 await self._wait_disconnect()
=C2= =A0 File "/home/niteesh/development/qemu/python/qemu/aqmp/protocol.py&= quot;, line 583, in _wait_disconnect
=C2=A0 =C2=A0 self._cleanup()
= =C2=A0 File "/home/niteesh/development/qemu/python/qemu/aqmp/qmp_clien= t.py", line 331, in _cleanup
=C2=A0 =C2=A0 super()._cleanup()
= =C2=A0 File "/home/niteesh/development/qemu/python/qemu/aqmp/protocol.= py", line 597, in _cleanup
=C2=A0 =C2=A0 assert self.runstate =3D= =3D Runstate.DISCONNECTING
AssertionError
-----------------------------------------------------------------= --------------------------

Hm, OK. I'm not sure if this is a bug on my part or not yet, I'll= investigate.
=C2=A0
=C2=A0 =C2=A0 =C2=A0def add_to_history(self, msg: str, level: Optional[str]= =3D None) -> None:
@@ -119,7 +132,7 @@ def _cb_inbound(self, msg: Message) -> Message:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0LOGGER.info('Error serv= er disconnected before reply')
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0urwid.emit_signal(self, UPD= ATE_MSG,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0'{"error": "Server= disconnected before reply"}')
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self._set_status("Server di= sconnected")
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 await self.disconnect()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0except Exception as err:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0LOGGER.error('Exception= from _send_to_server: %s', str(err))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0raise err
@@ -136,15 +149,29 @@ def kill_app(self) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0create_task(self._kill_app())
Is this required? I would= have hoped that after calling disconnect that the state would have again c= hanged to IDLE and you wouldn't need this clause here.
<= /div>
After you mentioned i= t I too felt it was redundant. But on removing it the whole app freezes whe= n trying to exit.
I logged the st= ate after the call to disconnect, instead of being in the IDLE state, it is= still in DISCONNECTING state.
I suspec= t this results in the constant infinite looping which doesn't give othe= r coroutines a chance to run and blocks
the event loop thus resulting in the freezing of the app. But I am not sur= e why the state isn't changing to IDLE.
<= div>
Hmm ... That may well be a bug in AQMP then. I will inve= stigate.
--0000000000008e9cd705c9da8db8--