]> git.proxmox.com Git - mirror_qemu.git/commitdiff
python/aqmp: handle asyncio.TimeoutError on execute()
authorJohn Snow <jsnow@redhat.com>
Mon, 10 Jan 2022 23:28:46 +0000 (18:28 -0500)
committerJohn Snow <jsnow@redhat.com>
Fri, 21 Jan 2022 21:01:31 +0000 (16:01 -0500)
This exception can be injected into any await statement. If we are
canceled via timeout, we want to clear the pending execution record on
our way out.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Beraldo Leal <bleal@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
python/qemu/aqmp/qmp_client.py

index 8105e29fa8f04297ec9390ec25ea518298e76639..6a985ffe30e651bcafd59df64e21183f64170ed7 100644 (file)
@@ -435,7 +435,11 @@ class QMPClient(AsyncProtocol[Message], Events):
             msg_id = msg['id']
 
         self._pending[msg_id] = asyncio.Queue(maxsize=1)
-        await self._outgoing.put(msg)
+        try:
+            await self._outgoing.put(msg)
+        except:
+            del self._pending[msg_id]
+            raise
 
         return msg_id
 
@@ -452,9 +456,9 @@ class QMPClient(AsyncProtocol[Message], Events):
             was lost, or some other problem.
         """
         queue = self._pending[msg_id]
-        result = await queue.get()
 
         try:
+            result = await queue.get()
             if isinstance(result, ExecInterruptedError):
                 raise result
             return result