修訂 | 3b5bf136f5798a4ea2c66875d6337ca3d6b79434 (tree) |
---|---|
時間 | 2022-01-22 06:01:31 |
作者 | John Snow <jsnow@redh...> |
Commiter | John Snow |
python/aqmp: handle asyncio.TimeoutError on execute()
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>
@@ -435,7 +435,11 @@ class QMPClient(AsyncProtocol[Message], Events): | ||
435 | 435 | msg_id = msg['id'] |
436 | 436 | |
437 | 437 | self._pending[msg_id] = asyncio.Queue(maxsize=1) |
438 | - await self._outgoing.put(msg) | |
438 | + try: | |
439 | + await self._outgoing.put(msg) | |
440 | + except: | |
441 | + del self._pending[msg_id] | |
442 | + raise | |
439 | 443 | |
440 | 444 | return msg_id |
441 | 445 |
@@ -452,9 +456,9 @@ class QMPClient(AsyncProtocol[Message], Events): | ||
452 | 456 | was lost, or some other problem. |
453 | 457 | """ |
454 | 458 | queue = self._pending[msg_id] |
455 | - result = await queue.get() | |
456 | 459 | |
457 | 460 | try: |
461 | + result = await queue.get() | |
458 | 462 | if isinstance(result, ExecInterruptedError): |
459 | 463 | raise result |
460 | 464 | return result |