fix(gateway): debounce restart with single-flight queue (#248)

Root cause for #243 / #244 / #240: model edits trigger
api.restartGateway() with only 300ms debounce. Fast consecutive
edits stack up restart calls, creating zombie Gateway processes,
failed restarts, and CPU fan spikes.

Layer A (frontend):
- New src/lib/gateway-restart-queue.js: 3s debounce + single-flight
  lock + reschedule on in-flight request
- Refactor src/pages/models.js doAutoSave: write config immediately,
  schedule restart via queue with 'Apply now' toast button
- Subscribe to queue state for unified success/failure toast
- Add i18n: models.configQueued, models.applyNow

Layer B (backend):
- src-tauri/src/commands/config.rs: wrap restart_gateway /
  reload_gateway with tokio::sync::Mutex + 2s cooldown
- Cargo.toml: add tokio 'sync' feature
- scripts/dev-api.js: same guard for Web mode (inflight promise
  reuse + 2s cooldown)

Effects:
- 10 rapid edits within 3s -> 1 restart (was 10+ with races)
- Backend serializes concurrent restart calls, no zombie spawns
- User sees single 'Apply now' toast instead of restart storm

Refs #243 #244 #240
This commit is contained in:
晴天
2026-04-24 19:35:39 +08:00
committed by GitHub
parent 66e57adab0
commit 5235853373
6 changed files with 273 additions and 42 deletions

View File

@@ -148,6 +148,8 @@ export default {
saveFailed: _('保存失败', 'Save failed', '儲存失敗', '保存失敗', '저장 실패'),
autoSaveFailed: _('自动保存失败', 'Auto-save failed', '自動儲存失敗'),
configSavedRestarting: _('配置已保存,正在重启 Gateway...', 'Config saved, restarting Gateway...', '設定已儲存,正在重啟 Gateway...'),
configQueued: _('配置已保存,即将重载 Gateway…', 'Config saved. Gateway will reload shortly…', '設定已儲存,即將重載 Gateway…'),
applyNow: _('立即生效', 'Apply now', '立即生效'),
configEffective: _('配置已生效Gateway 已重启', 'Config applied, Gateway restarted', '設定已生效Gateway 已重啟'),
retryRestart: _('重试', 'Retry', '重試'),
restarting: _('正在重启 Gateway...', 'Restarting Gateway...', '正在重啟 Gateway...'),