[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 09/11] python/aqmp: fix race condition in legacy.py
From: |
John Snow |
Subject: |
[PULL 09/11] python/aqmp: fix race condition in legacy.py |
Date: |
Mon, 7 Mar 2022 17:15:05 -0500 |
legacy.py provides a synchronous model. iotests frequently uses this
paradigm:
- create QMP client object
- start QEMU process
- await connection from QEMU process
In the switch from sync to async QMP, the QMP client object stopped
calling bind() and listen() during the QMP object creation step, which
creates a race condition if the QEMU process dials in too quickly.
With refactoring out of the way, restore the former behavior of calling
bind() and listen() during __init__() to fix this race condition.
Signed-off-by: John Snow <jsnow@redhat.com>
Acked-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-id: 20220225205948.3693480-10-jsnow@redhat.com
[Expanded commit message. --js]
Signed-off-by: John Snow <jsnow@redhat.com>
---
python/qemu/aqmp/legacy.py | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/python/qemu/aqmp/legacy.py b/python/qemu/aqmp/legacy.py
index dca1e76ed4..cb50e60564 100644
--- a/python/qemu/aqmp/legacy.py
+++ b/python/qemu/aqmp/legacy.py
@@ -57,7 +57,7 @@ def __init__(self, address: SocketAddrT,
self._timeout: Optional[float] = None
if server:
- self._aqmp._bind_hack(address) # pylint: disable=protected-access
+ self._sync(self._aqmp.start_server(address))
_T = TypeVar('_T')
@@ -90,10 +90,7 @@ def accept(self, timeout: Optional[float] = 15.0) ->
QMPMessage:
self._aqmp.await_greeting = True
self._aqmp.negotiate = True
- self._sync(
- self._aqmp.start_server_and_accept(self._address),
- timeout
- )
+ self._sync(self._aqmp.accept(), timeout)
ret = self._get_greeting()
assert ret is not None
--
2.34.1
- [PULL 00/11] Python patches, John Snow, 2022/03/07
- [PULL 05/11] python/aqmp: squelch pylint warning for too many lines, John Snow, 2022/03/07
- [PULL 06/11] python/aqmp: refactor _do_accept() into two distinct steps, John Snow, 2022/03/07
- [PULL 07/11] python/aqmp: stop the server during disconnect(), John Snow, 2022/03/07
- [PULL 03/11] python/aqmp: remove _new_session and _establish_connection, John Snow, 2022/03/07
- [PULL 01/11] python/aqmp: add _session_guard(), John Snow, 2022/03/07
- [PULL 04/11] python/aqmp: split _client_connected_cb() out as _incoming(), John Snow, 2022/03/07
- [PULL 10/11] python/aqmp: drop _bind_hack(), John Snow, 2022/03/07
- [PULL 02/11] python/aqmp: rename 'accept()' to 'start_server_and_accept()', John Snow, 2022/03/07
- [PULL 08/11] python/aqmp: add start_server() and accept() methods, John Snow, 2022/03/07
- [PULL 09/11] python/aqmp: fix race condition in legacy.py,
John Snow <=
- [PULL 11/11] scripts/qmp-shell-wrap: Fix import path, John Snow, 2022/03/07
- Re: [PULL 00/11] Python patches, Peter Maydell, 2022/03/08