1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-11 12:46:49 +00:00

fix(console): serial sessions start under a lock and say why they are refused

- socketiod's handlers run on their own threads. A connection is now
  admitted under a lock, so two at once can no longer both open a VM's
  console or pass the session cap. A session's terminal is used and closed
  only under its own lock while it is open: a closed descriptor's number,
  taken again by a new session, never receives another session's input
  or gives it the other's output.
- A refused connection says why: serial console off, the link expired,
  the VM's console open in another window, too many consoles. The page
  shows it instead of "refused".
- The page no longer retries on its own with a token that has expired
  after two minutes; Reconnect loads a new page. Input the browser cannot
  encode no longer raises in the daemon.
This commit is contained in:
catborise 2026-10-26 19:24:58 +03:00
parent 294b008811
commit 1fac3de23c
3 changed files with 108 additions and 45 deletions

View file

@ -23,8 +23,9 @@
<div id="terminal"></div>
<script>
// socketiod is behind this page's own /socket.io/ location; the page's
// signed token is the credential (the cookie holds the last console's)
var socket = io({transports: ["websocket", "polling"], auth: {token: "{{ token|escapejs }}"}});
// signed token is the credential. It lasts two minutes: a new
// connection takes a new page (Reconnect), not an automatic retry.
var socket = io({transports: ["websocket", "polling"], auth: {token: "{{ token|escapejs }}"}, reconnection: false});
const status = document.getElementById("status");
const button = document.getElementById("button");
@ -49,12 +50,12 @@
function showStatus(text, color) {
status.textContent = text;
status.style.backgroundColor = color;
button.textContent = socket.connected ? "Disconnect" : "Connect";
button.textContent = socket.connected ? "{% trans 'Disconnect'|escapejs %}" : "{% trans 'Reconnect'|escapejs %}";
}
socket.on("connect", () => showStatus("connected", "lightgreen"));
socket.on("disconnect", () => showStatus("disconnected", "#ff8383"));
// refused: serial console off, an expired token, or the VM's console already open
socket.on("connect_error", () => showStatus("refused", "#ff8383"));
socket.on("connect", () => showStatus("{% trans 'connected'|escapejs %}", "lightgreen"));
socket.on("disconnect", () => showStatus("{% trans 'disconnected'|escapejs %}", "#ff8383"));
// the server says why: serial console off, an expired link, the console open elsewhere
socket.on("connect_error", (err) => showStatus(err.message, "#ff8383"));
function myFunction(){
if (socket.connected) {