From 16ad625cda6d445f7803cb705d1339646ba83e43 Mon Sep 17 00:00:00 2001 From: catborise Date: Tue, 10 Nov 2026 18:58:20 +0300 Subject: [PATCH] fix(console): a console the server closes says Connection lost, not Disconnected The VNC and serial pages showed "Disconnected", as if the user had ended the session, when the VM stopped, was migrated or the console daemon restarted: noVNC calls a close by the server clean, and the serial page had a single text. "Disconnected" is now kept for the user's own Disconnect; any other end of a working connection is "Connection lost" (the serial terminal still prints the server's reason). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea --- console/templates/console-xterm.html | 1 + static/js/console_serial.js | 5 +++-- static/js/console_vnc.js | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/console/templates/console-xterm.html b/console/templates/console-xterm.html index 7a93f754..050bf664 100644 --- a/console/templates/console-xterm.html +++ b/console/templates/console-xterm.html @@ -14,6 +14,7 @@ {% block navbarstatus %} {% trans "Connecting" %} {% endblock %} diff --git a/static/js/console_serial.js b/static/js/console_serial.js index 4a0e34bc..89042cdf 100644 --- a/static/js/console_serial.js +++ b/static/js/console_serial.js @@ -58,13 +58,14 @@ socket.on('connect', () => { socket.on('taken_over', (data) => { takenBy = data.by; }); -socket.on('disconnect', () => { +socket.on('disconnect', (reason) => { if (takenBy) { const text = status.dataset.takenOver.replace('%(name)s', takenBy); term.write('\r\n[' + text + ']\r\n'); showStatus(text, 'danger'); } else { - showStatus(status.dataset.disconnected, 'danger'); + // the user's Disconnect, or the server's end (the terminal says why) or a lost connection + showStatus(reason === 'io client disconnect' ? status.dataset.disconnected : status.dataset.lost, 'danger'); } }); // the server says why: serial console off, an expired link, the console open elsewhere diff --git a/static/js/console_vnc.js b/static/js/console_vnc.js index 9655eb80..3c1f8897 100644 --- a/static/js/console_vnc.js +++ b/static/js/console_vnc.js @@ -23,6 +23,7 @@ const rfb = new RFB(document.getElementById('screen'), url, let connected = false; let closed = false; +let disconnecting = false; // the user's Disconnect, not a lost connection let refusal = null; function showStatus(text, color) { @@ -47,7 +48,8 @@ rfb.addEventListener('disconnect', (e) => { } else if (!connected) { showStatus(status.dataset.failed, 'danger'); } else { - showStatus(e.detail.clean ? status.dataset.disconnected : status.dataset.lost, 'danger'); + // noVNC calls a server's close clean too: the VM's stop, a migration, a restarted proxy + showStatus(disconnecting ? status.dataset.disconnected : status.dataset.lost, 'danger'); } connectionButton.textContent = connectionButton.dataset.reconnect; credentialsDialog.hide(); @@ -58,6 +60,7 @@ connectionButton.addEventListener('click', () => { if (closed) { window.location.reload(); } else { + disconnecting = true; rfb.disconnect(); } });