fix: tolerate QMP socket removal during status probes

This commit is contained in:
Codex
2026-10-13 04:24:38 +03:00
parent 7676389945
commit 46de8e25aa
2 changed files with 17 additions and 2 deletions
+4 -2
View File
@@ -182,9 +182,11 @@ class Runtime:
raise RuntimeError(f'Cannot verify VM identity: {exc}') from exc
def _listening(self, path: Path) -> bool:
if not path.exists():
try:
mode = path.lstat().st_mode
except FileNotFoundError:
return False
if not stat.S_ISSOCK(path.lstat().st_mode):
if not stat.S_ISSOCK(mode):
raise RuntimeError(f'Refusing non-socket runtime path: {path}')
with socket.socket(socket.AF_UNIX) as probe:
probe.settimeout(min(1, self.boot_timeout))
+13
View File
@@ -105,6 +105,19 @@ class RuntimeTests(unittest.TestCase):
self.assertNotIn('-vnc', argv)
self.assertNotIn('-virtfs', argv)
def test_socket_removed_during_stat_is_safely_not_listening(self):
paths = self.runtime.paths('guest')
paths.qmp.parent.mkdir(parents=True)
with socket.socket(socket.AF_UNIX) as fixture:
fixture.bind(str(paths.qmp))
original_lstat = Path.lstat
def disappearing_socket(path):
if path == paths.qmp:
path.unlink(missing_ok=True)
return original_lstat(path)
with patch.object(Path, 'lstat', disappearing_socket):
self.assertFalse(self.runtime._listening(paths.qmp))
def test_argv_provides_audio_and_manual_usb_channels(self):
argv = build_qemu_argv(self.profile, self.runtime.paths('guest'))
self.assertIn('spice,id=audio', argv)