Skip to contentSkip to conversation

qmp: Check for returned data from __json_read in get_events

PATCH Applied Fam Zheng 3 participants 3 messages Feb 24, 2014 – Feb 28, 2014

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH 1/1 qmp: Check for returned data from __json_read in get_events

When QEMU process aborts and socket is closed, qmp client will not detect it. When this happens, some qemu-iotests scripts will enter an endless loop waiting for qmp events.

It's better we raise an exception in qmp.py to catch this and make the test script stop.

---
 scripts/qmp/qmp.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
scripts/qmp/qmp.py +6 -1
index 5c97175..20b6ec7 100644
@@ -171,7 +171,12 @@ class QEMUMonitorProtocol:
                 pass
         self.__sock.setblocking(1)
         if not self.__events and wait:
-            self.__json_read(only_event=True)
+            ret = self.__json_read(only_event=True)
+            if ret == None:
+                # We are in blocking mode, if don't get anything, something
+                # went wrong
+                raise QMPConnectError("Error while reading from socket")
+
         return self.__events
 
     def clear_events(self):
Signature · 1 line
1.9.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Fam Zheng

When QEMU process aborts and socket is closed, qmp client will not detect it. When this happens, some qemu-iotests scripts will enter an endless loop waiting for qmp events.

It's better we raise an exception in qmp.py to catch this and make the test script stop.

---
 scripts/qmp/qmp.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
#2 lore raw
In reply to Fam Zheng
Quoted 8 lines · On Mon, 24 Feb 2014 13:45:01 +0800 Fam Zheng <[email protected]> wrote:

When QEMU process aborts and socket is closed, qmp client will not detect it. When this happens, some qemu-iotests scripts will enter an endless loop waiting for qmp events.

It's better we raise an exception in qmp.py to catch this and make the test script stop.

Applied to the qmp branch, thanks.

Quoted 22 lines
---
 scripts/qmp/qmp.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
scripts/qmp/qmp.py +6 -1
index 5c97175..20b6ec7 100644
@@ -171,7 +171,12 @@ class QEMUMonitorProtocol:
                 pass
         self.__sock.setblocking(1)
         if not self.__events and wait:
-            self.__json_read(only_event=True)
+            ret = self.__json_read(only_event=True)
+            if ret == None:
+                # We are in blocking mode, if don't get anything, something
+                # went wrong
+                raise QMPConnectError("Error while reading from socket")
+
         return self.__events
 
     def clear_events(self):