mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
fix: harden console self-update rollback and deployment checks
Recovered after the original 04bd82e object was lost from the worktree history; the working tree still contained the same ten-file fix (249 insertions).
This commit is contained in:
1 parent
2de2e23fd3
commit
eb6c4ba857
10 files changed
+249
-28
No files matched your search
@@ -465,10 +465,11 @@ export function createAdminRouter(options: AdminRouterOptions): Router {
|
||||
if (version !== confirmVersion) throw new UpdateError("UPDATE_CONFIRMATION_REQUIRED", "The confirmation does not match the selected version.");
|
||||
const task = await options.updateService.applyUpdate(version, confirmVersion);
|
||||
options.service.database.addAudit("ADMIN_UPDATE_STARTED", { version });
|
||||
response.once("finish", () => {
|
||||
setTimeout(() => options.restartAfterUpdate?.(), 250).unref();
|
||||
});
|
||||
response.status(202).json({ ok: true, task });
|
||||
// Do not wait for the response to finish: a reverse proxy or a client
|
||||
// that disconnects early must not leave the restart runner waiting for
|
||||
// this process until its timeout expires.
|
||||
setTimeout(() => options.restartAfterUpdate?.(), 250).unref();
|
||||
} catch (error: unknown) {
|
||||
sendUpdateError(response, error);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test, { type TestContext } from "node:test";
|
||||
import { mkdtempSync, rmSync } from "node:fs";
|
||||
import http from "node:http";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import express from "express";
|
||||
@@ -152,6 +153,30 @@ test("a confirmed apply returns the task and stops the process after the respons
|
||||
assert.equal(f.restarted(), true);
|
||||
});
|
||||
|
||||
test("a client that disconnects before the response still schedules the restart", async t => {
|
||||
const f = await fixture(t);
|
||||
const { cookie, csrf } = await f.login();
|
||||
const body = JSON.stringify({ version: "0.4.0", confirmVersion: "0.4.0" });
|
||||
const url = new URL(`${f.origin}/api/admin/update/apply`);
|
||||
const request = http.request({
|
||||
hostname: url.hostname, port: url.port, path: url.pathname, method: "POST",
|
||||
headers: {
|
||||
origin: f.origin, cookie, "x-csrf-token": csrf, "content-type": "application/json",
|
||||
"content-length": Buffer.byteLength(body),
|
||||
},
|
||||
});
|
||||
request.on("error", () => { /* Expected once the socket is destroyed. */ });
|
||||
request.end(body);
|
||||
const deadline = Date.now() + 2_000;
|
||||
while (f.applyCalls.length === 0 && Date.now() < deadline) await new Promise<void>((resolve) => setTimeout(resolve, 20));
|
||||
assert.deepEqual(f.applyCalls, [["0.4.0", "0.4.0"]]);
|
||||
// Close the connection without consuming the response. The restart must not
|
||||
// depend on the response finish event.
|
||||
request.destroy();
|
||||
await new Promise<void>((resolve) => setTimeout(resolve, 700));
|
||||
assert.equal(f.restarted(), true);
|
||||
});
|
||||
|
||||
test("update status and check return the service projections", async t => {
|
||||
const f = await fixture(t);
|
||||
const { cookie, csrf } = await f.login();
|
||||
|
||||
Reference in new issue
Block a user