1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-01 08:26:03 +00:00

fix(instances): an open VM page follows its VM's removal on the host

A VM undefined outside the panel (virsh, virt-manager) while its page was
open made the state and statistics polls answer 500 every 5 seconds, each
an error in the panel's log, and the page stayed as it was. A page read of
an object the host no longer has is now 404, and the VM page reloads on a
404 of its state: it then goes to the VM list with "no longer on its host",
or shows that the VM is not found.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
catborise 2026-11-09 21:22:33 +03:00
parent 373760f2c5
commit a2f4d3fe06
4 changed files with 45 additions and 14 deletions

View file

@ -1,17 +1,30 @@
// The VM page reloads when the VM's state changes (instance.html, #vm-summary).
// The VM page reloads when the VM's state changes (instance.html, #vm-summary),
// or when the VM is gone: the page then says so.
backgroundJobRunning = false;
// not "status": that is window.status, which the browser may not keep
var vm_summary = document.getElementById("vm-summary");
var vm_status = Number(vm_summary.dataset.status);
var host_lost = document.getElementById("vm-host-lost");
var status_poll = pollWhileVisible(5000, function () {
// a failed read (a host that does not answer, a session that ended) leaves the
// page as it was: it says so until a read is answered
return $.getJSON(vm_summary.dataset.statusUrl).fail(function () { host_lost.hidden = false; });
}, function get_status(data) {
host_lost.hidden = true;
function reloadWhenFree() {
// the page in use (a dialog open, a field in use, an XML edit not saved): the reload waits (poll.js)
if (data['status'] != vm_status && !backgroundJobRunning && !pageInUse()) {
if (!backgroundJobRunning && !pageInUse()) {
window.location.reload();
}
}
var status_poll = pollWhileVisible(5000, function () {
return $.getJSON(vm_summary.dataset.statusUrl).fail(function (xhr) {
// a failed read (a host that does not answer, a session that ended, the VM gone while
// the page is in use) leaves the page as it was: it says so until a read is answered
host_lost.hidden = false;
if (xhr.status == 404) {
reloadWhenFree();
}
});
}, function get_status(data) {
host_lost.hidden = true;
if (data['status'] != vm_status) {
reloadWhenFree();
}
});