pvpanic: Fix race condition when checking QMP events - #4416
Conversation
When guest triggers panic and QEMU exits quickly (especially on RHEL10), the test may fail with MonitorSocketError due to socket connection being reset while checking QMP events. Signed-off-by: Wenkang Ji <wji@redhat.com>
WalkthroughThis change modifies an event detection function in Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
qemu/tests/pvpanic.py (1)
54-67: MoveMonitorSocketErrorhandling outside_do_check()to avoid timeout waste and log spamWhen
MonitorSocketErroris caught inside_do_check()and returnsNone(falsy),wait_for()continues polling until the full timeout expires, logging "QMP connection closed" on every iteration. Sincewait_for()propagates exceptions from its callback and stops only on a truthy return, this turns a terminal condition into a slow, noisy timeout.Instead:
- Simplify
_do_check()to a clean "event present?" predicate returning onlyTrue/False- Wrap the
wait_for()call intry/except MonitorSocketErrorto log once and returnNoneimmediatelyThis preserves the external behavior (returns
Trueon success,Noneotherwise) without wasting the full timeout when QMP closes:def _do_check(vm, event_names): - try: - events = vm.monitor.get_events() - for event in events: - if event.get("event") in event_names: - LOG_JOB.info( - "Receive qmp %s event notification", event.get("event") - ) - vm.monitor.clear_event(event.get("event")) - return True - except MonitorSocketError: - LOG_JOB.warning("QMP connection closed") - return None + events = vm.monitor.get_events() + for event in events: + if event.get("event") in event_names: + LOG_JOB.info( + "Receive qmp %s event notification", event.get("event") + ) + vm.monitor.clear_event(event.get("event")) + return True return False - LOG_JOB.info("Try to get qmp events %s in %s seconds!", event_names, timeout) - return wait_for(lambda: _do_check(vm, event_names), timeout, 5, 5) + LOG_JOB.info("Try to get qmp events %s in %s seconds!", event_names, timeout) + try: + return wait_for(lambda: _do_check(vm, event_names), timeout, 5, 5) + except MonitorSocketError: + LOG_JOB.warning("QMP connection closed while waiting for events %s", event_names) + return None
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
qemu/tests/pvpanic.py(2 hunks)
🔇 Additional comments (1)
qemu/tests/pvpanic.py (1)
7-7: Import ofMonitorSocketErrorlooks correctThe new import cleanly scopes the QMP error handling to this module and matches its later usage in
check_qmp_events(). No issues here.
|
Test Result: PASS |
|
@leidwang Hi Leidong, could you please help review this patch? |
|
@fbq815 Hi Boqiao, could you please help review this patch and test it on your multi-arch platform? thanks! |
|
@fbq815 If no comments from your side, we will merge this PR later. |
|
Closing this PR due to current team constraints. This is part of a broader effort to triage all in-flight work across our upstream repos. If this work is still needed, please feel free to reopen and it will be picked up. Apologies for any inconvenience. |
When guest triggers panic and QEMU exits quickly (especially on RHEL10), the test may fail with MonitorSocketError due to socket connection being reset while checking QMP events.
ID: 1863
Signed-off-by: Wenkang Ji wji@redhat.com
Summary by CodeRabbit
Bug Fixes
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.