mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-01 08:26:03 +00:00
fix(vrtManager): reconnect after a host's storage or network daemon restarts
On a host with libvirt's modular daemons, a restart of virtstoraged or virtnetworkd (a package update, for one) left the panel's connection to virtproxyd open and alive, but every later storage or network call on it failed with "internal error: client socket is closed". Nothing replaced it: the storage and network pages showed the error and the VM page gave 500 until the panel was restarted, and a clone running then waited in recovery for up to an hour, holding its VM. libvirt reports that error as an RPC internal error and does not say on which connection, so the error handler now has the process retire its open connections at the next get_connection: each opens again when next asked. A retired connection stays with the threads that use them, its close callback unregistered so that it closes once they are done; a connection that failed or is opening keeps its retry delay. On compute1 the pages answered again from the second request on, and the clone's job failed at its first recovery check, 30 s later, freeing its VM. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
parent
aefe551450
commit
b70bab2144
2 changed files with 65 additions and 4 deletions
|
|
@ -177,6 +177,36 @@ class BoundedOpenTestCase(unittest.TestCase):
|
|||
self.assertIsNone(entry.connection)
|
||||
self.assertEqual(entry.last_error, {"text": "Connection closed (keepalive timeout)", "values": {}})
|
||||
|
||||
def test_an_rpc_error_opens_new_connections(self):
|
||||
self.release.set()
|
||||
old, new = alive_connection(), alive_connection()
|
||||
with self.open_auth(old):
|
||||
self.get()
|
||||
with patch("vrtManager.connection.connection_manager", self.manager):
|
||||
# another error keeps the connection
|
||||
connection._on_libvirt_error(None, (libvirt.VIR_ERR_NO_DOMAIN, libvirt.VIR_FROM_QEMU, "no domain", 2))
|
||||
self.assertIs(self.get()[0], old)
|
||||
# a restarted virtstoraged: the connection is alive, its storage calls fail for good
|
||||
connection._on_libvirt_error(None, (libvirt.VIR_ERR_INTERNAL_ERROR, libvirt.VIR_FROM_RPC,
|
||||
"internal error: client socket is closed", 2))
|
||||
with self.open_auth(new):
|
||||
self.assertIs(self.get()[0], new)
|
||||
self.assertIs(self.get()[0], new)
|
||||
old.close.assert_not_called() # a thread may still use it
|
||||
old.unregisterCloseCallback.assert_called_once() # else libvirt keeps it
|
||||
|
||||
def test_an_rpc_error_keeps_a_failed_hosts_retry_delay(self):
|
||||
self.release.set()
|
||||
with self.open_auth(libvirt.libvirtError("unable to connect")):
|
||||
self.get()
|
||||
with patch("vrtManager.connection.connection_manager", self.manager):
|
||||
connection._on_libvirt_error(None, (libvirt.VIR_ERR_INTERNAL_ERROR, libvirt.VIR_FROM_RPC,
|
||||
"internal error: client socket is closed", 2))
|
||||
with self.open_auth(alive_connection()):
|
||||
result, _took = self.get()
|
||||
self.assertIsInstance(result, libvirt.libvirtError) # still within RETRY_AFTER
|
||||
self.assertEqual(self.calls, 1)
|
||||
|
||||
def test_the_log_has_each_change_of_a_host_not_each_retry(self):
|
||||
self.release.set()
|
||||
conn = alive_connection()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue