fix(p2): 按审查清单修 103 条「建议修」+ 奖牌榜改名 + 两个守卫(dev_0.2.0)
## 奖牌榜改名(主人要求)
「团体奖牌榜」→「单位奖牌榜」,界面 / 大屏渲染页 / 导出件(工作表名与
下载文件名 `单位奖牌明细.xlsx`)/ 用户文档 全部统一;`DISPLAY_PAGES` 是
大屏控制页与大屏页的共同来源,改一处两边同时生效。旧名保留为别名,
老链接与老配置(`display.pages`)照常有效。真 Chromium 验证:14 个管理端
路由 + 7 个基础数据分区 0 报错,大屏页标题已是「单位奖牌榜」。
## P2 清单(123 条,103 条标「建议修」)
按 A/B/C/D 分组、以「文件所有权互斥」分 10 个代理并行推进,另有独立复核
代理逐条核对:61 条声称已修 / 55 条证实 / 4 条部分 / 0 条不成立 / 0 垃圾。
主要交付(按风险从高到低):
- 写入侧校验:update 路径补必填与 TrimSpace、模板 rules 重复 rank、
「小项不存在」的四种回答、`defaultProfileId` 外键、decodeJSON 的 8MB
上限与 413(A01–A06、D02、D03 批量上限 500)
- 危险操作:一键恢复加互斥(第二个请求当场 409)、恢复超时不再说
「未执行」、`ConfirmDialog` pending 时锁死 ESC/遮罩/关闭
- 认证:改密与撤会话进同一事务、滑动续期写库失败不再假装成功、
CSRF Cookie 丢失自动补发、密码长度按字符(原按字节)、
反代 403 只在可信代理透传原 Host 时采信 `X-Forwarded-Host`(全等比较)、
过期会话定期清理、登出补审计、登录限流可配
- 数据可见性:导出「已发布未结算」行改为 `名次 — / 积分 — / 状态未结算`、
单位积分明细成绩列与其它导出件逐字一致、空单位也打合计行、
基础数据包命中「已彻底删除的单位」整行跳过并报界面路径、
报名导入换单位给明确提示、勾选报名有冲突不再假报成功
- 导入/导出:赛事包上限 512MB(**它是唯一带字体/图片的包**,字体上限
20MB)而 multipart 内存档位独立钉在 16MB、工作簿表名尾随空格、
导出件路由与文件名契约补全
- 前端:一次写请求只生成一个 requestId(幂等缓存此前从未命中)、
基础数据包补 `X-Request-Id`、示例数据模式禁写扩到撤销发布/存草稿、
访客 401 不再是裸错误、模板 `{{else if}}` 不再静默吞内容
- Console:按设计退出(切赛事/恢复)不再判成崩溃、旧数据目录读不出来
会记日志、渲染层日志按上限截断、`service.js` 补 17 例测试
## 测试
服务端用例 610 → 674(13 包全绿,新增老库跨九条迁移升级、panic 形状、
429 落 interceptions、三态对照、avg_mode 分母、会话失效、请求体上限等)
前端 449 → 531(vue-tsc + build 通过);Console 28 → 54(19 个文件)。
另修复一条会让整包挂死 600s 的用例(测试主协程堵在 client.Do,defer
轮不到执行 → 改为可取消 + 探针超时,改坏也 7.5s 快速失败)。
## 两个新守卫(防止再出现「组件 setup 抛异常」这类盲区)
- `web/scripts/check-declaration-order.mjs` 已进测试命令:沿 watch/
watchEffect 的 const 依赖链查 TDZ(正是「运动员页整块空白」的根因)
- `web/scripts/smoke-admin.mjs`(`pnpm smoke`):真 Chromium 点遍 14 个
管理端路由 + 7 个基础数据分区 + 大屏页,任何 console 错误即失败
## 文档
- `docs/升级说明.md` 新增 dev_0.2.0 一节(三件升级必知:改名、审计前缀
与历史记录、密码口径;现场变化;赛事包上限;反代与 CSRF)
- 使用手册 / 常见问题 / 部署指南 / 上线检查清单按实现同步
This commit is contained in:
1 parent
db94d9c119
commit
6841cf49aa
147 files changed
+8141
-423
No files matched your search
+100
-29
@@ -14,6 +14,9 @@ const STATE_LABEL = {
|
||||
starting: '启动中',
|
||||
running: '运行中',
|
||||
stopping: '停止中',
|
||||
// 服务端自己按设计退出(切换赛事 / 一键恢复)后的等待期:与「异常退出」必须分开显示,
|
||||
// 现场看到红灯会以为服务挂了,实际是正常收尾等 Console 拉回来。
|
||||
restarting: '重启中',
|
||||
crashed: '异常退出'
|
||||
}
|
||||
|
||||
@@ -29,6 +32,18 @@ const DEFAULT_SHUTDOWN_TIMEOUT_MS = 5000
|
||||
const FALLBACK_FORCE_KILL_MS = 1500
|
||||
// 连续健康这么久才认为崩溃计数可以清零
|
||||
const HEALTHY_RESET_MS = 60000
|
||||
// 「预期退出窗口」的下限:最后一次确认服务端还活着之后的这段时间内退出,才可能是按设计退出。
|
||||
// 健康探测默认 5 秒一次,窗口至少覆盖两三个探测周期,避免刚好卡在探测空档时漏判。
|
||||
const EXPECTED_EXIT_WINDOW_MS = 15000
|
||||
|
||||
// 副作用边界集中在这里注入:进程、时钟、HTTP。生产路径直接用 Node 的实现,
|
||||
// 单元测试传假实现,才能在毫秒内跑完退避、超时、优雅关闭这些真实要等几秒的分支。
|
||||
const defaultTimers = {
|
||||
setTimeout: (fn, ms) => setTimeout(fn, ms),
|
||||
clearTimeout: (id) => clearTimeout(id),
|
||||
setInterval: (fn, ms) => setInterval(fn, ms),
|
||||
clearInterval: (id) => clearInterval(id)
|
||||
}
|
||||
|
||||
// 服务端可能监听 0.0.0.0/::,本机访问(健康检查、关闭握手、大屏、管理面板)统一走回环地址
|
||||
function healthHost(server) {
|
||||
@@ -39,7 +54,7 @@ function healthHost(server) {
|
||||
// 服务端守护:拉起 scoreboard.exe、转发日志、健康探测、崩溃自动重启。
|
||||
// 现场无人值守,所以「崩了自动拉起」比「暴露复杂控制」更重要。
|
||||
class ServiceSupervisor extends EventEmitter {
|
||||
constructor({ values, exePath, log, dataDir, configPath }) {
|
||||
constructor({ values, exePath, log, dataDir, configPath, spawn: spawnFn, http: httpClient, timers, now }) {
|
||||
super()
|
||||
this.values = values
|
||||
this.server = values.server
|
||||
@@ -50,6 +65,12 @@ class ServiceSupervisor extends EventEmitter {
|
||||
// 绝对路径,非空时覆盖 args 里的 -config;为空表示沿用 args 原值(开发态)
|
||||
this.configPath = configPath || null
|
||||
|
||||
// 可注入的副作用边界,默认就是 Node 的实现
|
||||
this.spawn = spawnFn || spawn
|
||||
this.http = httpClient || http
|
||||
this.timers = { ...defaultTimers, ...(timers || {}) }
|
||||
this.now = now || (() => Date.now())
|
||||
|
||||
this.child = null
|
||||
this.state = 'stopped'
|
||||
this.healthy = false
|
||||
@@ -60,6 +81,9 @@ class ServiceSupervisor extends EventEmitter {
|
||||
|
||||
this.stopRequested = false
|
||||
this.healthySince = null
|
||||
this.disposed = false
|
||||
// 最近一次确认服务端还在正常服务(健康检查通过)的时刻,用于「预期退出窗口」判定
|
||||
this.lastAliveAt = null
|
||||
this.healthTimer = null
|
||||
this.restartTimer = null
|
||||
this.forceKillTimer = null
|
||||
@@ -128,9 +152,12 @@ class ServiceSupervisor extends EventEmitter {
|
||||
|
||||
this.lastError = null
|
||||
this.healthySince = null
|
||||
// 新进程重新起算「还活着」的时刻:否则上一个进程的健康记录会让
|
||||
// 「刚起来就退出 0」被误判成按设计退出
|
||||
this.lastAliveAt = null
|
||||
this.gracefulAccepted = false
|
||||
this.forcedKill = false
|
||||
this.startedAt = new Date().toISOString()
|
||||
this.startedAt = new Date(this.now()).toISOString()
|
||||
this.setState('starting')
|
||||
this.log.push(
|
||||
'console',
|
||||
@@ -143,7 +170,7 @@ class ServiceSupervisor extends EventEmitter {
|
||||
|
||||
let child
|
||||
try {
|
||||
child = spawn(this.exePath, spawnArgs, {
|
||||
child = this.spawn(this.exePath, spawnArgs, {
|
||||
cwd,
|
||||
windowsHide: true,
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
@@ -183,7 +210,7 @@ class ServiceSupervisor extends EventEmitter {
|
||||
// 必须在这里清掉 child/pid 并调度重启,否则 start() 因 child 非空直接返回、
|
||||
// stop() 永远等不到 exit,守护器彻底卡死。
|
||||
handleSpawnError(child, err) {
|
||||
if (this.child !== child) return
|
||||
if (this.disposed || this.child !== child) return
|
||||
this.stopHealthCheck()
|
||||
this.child = null
|
||||
this.pid = null
|
||||
@@ -194,10 +221,11 @@ class ServiceSupervisor extends EventEmitter {
|
||||
}
|
||||
|
||||
handleExit(child, code, signal) {
|
||||
// 迟到的 exit(error 分支已收尾或已换进程)不能动当前状态
|
||||
if (this.child !== child) return
|
||||
// 迟到的 exit(error 分支已收尾、已换进程、或已经 dispose)不能动当前状态;
|
||||
// 尤其是 dispose 之后:应用正在退出,这里再排一次自动重启会留下一个没人管的循环
|
||||
if (this.disposed || this.child !== child) return
|
||||
if (this.forceKillTimer) {
|
||||
clearTimeout(this.forceKillTimer)
|
||||
this.timers.clearTimeout(this.forceKillTimer)
|
||||
this.forceKillTimer = null
|
||||
}
|
||||
this.stopHealthCheck()
|
||||
@@ -216,22 +244,60 @@ class ServiceSupervisor extends EventEmitter {
|
||||
return
|
||||
}
|
||||
|
||||
if (this.isPlannedExit(code)) {
|
||||
// 切换赛事 / 一键恢复:服务端先回执再自行优雅退出,Console 的职责是把它拉回来。
|
||||
// 这不能按崩溃算——否则现场正常切个赛事会显示红灯、崩溃计数 +1。
|
||||
this.log.push('console', `服务端按设计退出(${reason},切换赛事 / 一键恢复),准备自动拉起`)
|
||||
this.setState('restarting', { lastError: null })
|
||||
this.scheduleRestart({ planned: true })
|
||||
return
|
||||
}
|
||||
|
||||
this.setState('crashed', { lastError: `服务端意外退出(${reason})` })
|
||||
this.scheduleRestart()
|
||||
}
|
||||
|
||||
scheduleRestart() {
|
||||
// 「按设计退出」的判定窗口(毫秒):最后一次确认服务端还活着之后允许退出的时间。
|
||||
// 健康间隔配得大时窗口跟着放大,至少覆盖两个探测周期。
|
||||
expectedExitWindowMs() {
|
||||
const interval = Number(this.server.healthIntervalMs) || 5000
|
||||
return Math.max(EXPECTED_EXIT_WINDOW_MS, interval * 2)
|
||||
}
|
||||
|
||||
// 服务端主动退出(退出码 0)与崩溃靠两点区分:
|
||||
// 1) 退出码:Go 只有从 main 正常返回才是 0,panic 是 2、装配失败是 os.Exit(1)、被信号杀则没有退出码;
|
||||
// 2) 是否在预期退出窗口内:切换赛事 / 一键恢复一定发生在服务端刚刚还在正常服务的时候
|
||||
// (管理面板先拿到 200 回执,服务端随后才 Shutdown),所以窗口从最后一次健康检查通过起算。
|
||||
// 窗口外退出 0 说明这次运行从没健康过,那不是切赛事而是异常,仍旧按崩溃处理。
|
||||
isPlannedExit(code) {
|
||||
return (
|
||||
code === 0 &&
|
||||
this.lastAliveAt !== null &&
|
||||
this.now() - this.lastAliveAt <= this.expectedExitWindowMs()
|
||||
)
|
||||
}
|
||||
|
||||
// planned=true 表示按设计退出后的拉起:不占崩溃配额、不递增崩溃计数,
|
||||
// 延迟仍用 restartDelayMs——服务端刚退出,端口与文件句柄要留一点回收时间。
|
||||
scheduleRestart({ planned = false } = {}) {
|
||||
const max = Number(this.server.maxRestarts) || 0
|
||||
if (max > 0 && this.restarts >= max) {
|
||||
if (!planned && max > 0 && this.restarts >= max) {
|
||||
this.log.push('console', `已达到最大重启次数 ${max},不再自动拉起`)
|
||||
return
|
||||
}
|
||||
const delay = (Number(this.server.restartDelayMs) || 3000) * Math.min(this.restarts + 1, 5)
|
||||
this.restarts += 1
|
||||
this.log.push('console', `${Math.round(delay / 1000)} 秒后自动重启服务端(第 ${this.restarts} 次)`)
|
||||
// 退避是线性的 ×1..×5(不是翻倍):第 N 次等 N × restartDelayMs
|
||||
const attempt = planned ? 1 : this.restarts + 1
|
||||
const delay = (Number(this.server.restartDelayMs) || 3000) * Math.min(attempt, 5)
|
||||
if (!planned) this.restarts += 1
|
||||
this.log.push(
|
||||
'console',
|
||||
planned
|
||||
? `${Math.round(delay / 1000)} 秒后自动拉起服务端(按设计退出,不计入崩溃次数)`
|
||||
: `${Math.round(delay / 1000)} 秒后自动重启服务端(第 ${this.restarts} 次)`
|
||||
)
|
||||
this.emitStatus()
|
||||
if (this.restartTimer) clearTimeout(this.restartTimer)
|
||||
this.restartTimer = setTimeout(() => {
|
||||
if (this.restartTimer) this.timers.clearTimeout(this.restartTimer)
|
||||
this.restartTimer = this.timers.setTimeout(() => {
|
||||
this.restartTimer = null
|
||||
if (!this.stopRequested) this.start()
|
||||
}, delay)
|
||||
@@ -240,7 +306,7 @@ class ServiceSupervisor extends EventEmitter {
|
||||
stop() {
|
||||
return new Promise((resolve) => {
|
||||
if (this.restartTimer) {
|
||||
clearTimeout(this.restartTimer)
|
||||
this.timers.clearTimeout(this.restartTimer)
|
||||
this.restartTimer = null
|
||||
}
|
||||
const child = this.child
|
||||
@@ -260,7 +326,7 @@ class ServiceSupervisor extends EventEmitter {
|
||||
if (settled) return
|
||||
settled = true
|
||||
if (this.stopTimer) {
|
||||
clearTimeout(this.stopTimer)
|
||||
this.timers.clearTimeout(this.stopTimer)
|
||||
this.stopTimer = null
|
||||
}
|
||||
resolve()
|
||||
@@ -268,7 +334,7 @@ class ServiceSupervisor extends EventEmitter {
|
||||
|
||||
// 兜底:握手与强杀链路都可能因进程状态异常收不到 exit,
|
||||
// 退出流程不能永远挂住,超时后无条件放行并补一刀强杀。
|
||||
this.stopTimer = setTimeout(() => {
|
||||
this.stopTimer = this.timers.setTimeout(() => {
|
||||
this.stopTimer = null
|
||||
this.log.push('console', '等待服务端退出超时,停止流程强制返回')
|
||||
if (this.child === child) {
|
||||
@@ -313,7 +379,7 @@ class ServiceSupervisor extends EventEmitter {
|
||||
requestShutdown() {
|
||||
return new Promise((resolve) => {
|
||||
const body = Buffer.from('{}')
|
||||
const request = http.request(
|
||||
const request = this.http.request(
|
||||
{
|
||||
host: this.healthHost(),
|
||||
port: this.server.port,
|
||||
@@ -344,8 +410,8 @@ class ServiceSupervisor extends EventEmitter {
|
||||
}
|
||||
|
||||
armForceKill(ms) {
|
||||
if (this.forceKillTimer) clearTimeout(this.forceKillTimer)
|
||||
this.forceKillTimer = setTimeout(() => {
|
||||
if (this.forceKillTimer) this.timers.clearTimeout(this.forceKillTimer)
|
||||
this.forceKillTimer = this.timers.setTimeout(() => {
|
||||
this.forceKillTimer = null
|
||||
if (!this.child || !this.pid) return
|
||||
this.forcedKill = true
|
||||
@@ -368,20 +434,20 @@ class ServiceSupervisor extends EventEmitter {
|
||||
this.stopHealthCheck()
|
||||
const interval = Number(this.server.healthIntervalMs) || 5000
|
||||
const tick = () => this.probe()
|
||||
setTimeout(tick, 800)
|
||||
this.healthTimer = setInterval(tick, interval)
|
||||
this.timers.setTimeout(tick, 800)
|
||||
this.healthTimer = this.timers.setInterval(tick, interval)
|
||||
}
|
||||
|
||||
stopHealthCheck() {
|
||||
if (this.healthTimer) {
|
||||
clearInterval(this.healthTimer)
|
||||
this.timers.clearInterval(this.healthTimer)
|
||||
this.healthTimer = null
|
||||
}
|
||||
}
|
||||
|
||||
probe() {
|
||||
if (!this.child) return
|
||||
const request = http.get(
|
||||
const request = this.http.get(
|
||||
{
|
||||
host: this.healthHost(),
|
||||
port: this.server.port,
|
||||
@@ -401,7 +467,9 @@ class ServiceSupervisor extends EventEmitter {
|
||||
setHealthy(ok) {
|
||||
const changed = this.healthy !== ok
|
||||
if (ok) {
|
||||
if (!this.healthySince) this.healthySince = Date.now()
|
||||
// 探测通过 = 这一刻服务端还在正常服务,是「预期退出窗口」的起算点
|
||||
this.lastAliveAt = this.now()
|
||||
if (!this.healthySince) this.healthySince = this.now()
|
||||
} else {
|
||||
this.healthySince = null
|
||||
}
|
||||
@@ -415,7 +483,7 @@ class ServiceSupervisor extends EventEmitter {
|
||||
let reset = false
|
||||
if (ok && this.restarts > 0) {
|
||||
const resetAfter = Number(this.server.healthyResetMs) || HEALTHY_RESET_MS
|
||||
if (Date.now() - this.healthySince >= resetAfter) {
|
||||
if (this.now() - this.healthySince >= resetAfter) {
|
||||
this.restarts = 0
|
||||
reset = true
|
||||
this.log.push('console', '服务端持续健康,崩溃计数已清零')
|
||||
@@ -426,9 +494,12 @@ class ServiceSupervisor extends EventEmitter {
|
||||
}
|
||||
|
||||
dispose() {
|
||||
if (this.restartTimer) clearTimeout(this.restartTimer)
|
||||
if (this.forceKillTimer) clearTimeout(this.forceKillTimer)
|
||||
if (this.stopTimer) clearTimeout(this.stopTimer)
|
||||
// dispose 之后连子进程的 exit 都不再处理(见 handleExit 的守卫),
|
||||
// 否则「应用已退出、子进程后死」会重新排一次重启,留下一个没人观察的守护循环
|
||||
this.disposed = true
|
||||
if (this.restartTimer) this.timers.clearTimeout(this.restartTimer)
|
||||
if (this.forceKillTimer) this.timers.clearTimeout(this.forceKillTimer)
|
||||
if (this.stopTimer) this.timers.clearTimeout(this.stopTimer)
|
||||
this.stopHealthCheck()
|
||||
this.removeAllListeners()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user