fix(server): require at least five minutes of maintenance countdown
Idle game clients only poll the server every three minutes, so a shorter countdown could reach players only after maintenance had started. Schedule now accepts 0 (start now) or 5 minutes to 24 hours, updates.json validates its default countdown the same way, and the console explains the rule in every language.
This commit is contained in:
1 parent
219b25becf
commit
27bde103be
8 files changed
+46
-8
No files matched your search
@@ -29,7 +29,7 @@
|
||||
"console.error.no_update": "No newer server release is available.",
|
||||
"console.error.already_scheduled": "A maintenance is already scheduled.",
|
||||
"console.error.irreversible_unconfirmed": "This release contains a save migration that cannot be rolled back. Read the migration note and confirm it first.",
|
||||
"console.error.invalid_delay": "The countdown must be between 0 and 1,440 minutes (24 hours).",
|
||||
"console.error.invalid_delay": "The countdown must be 0 (start now) or between 5 and 1,440 minutes (24 hours), so idle players still see the warning.",
|
||||
"console.error.install_not_writable": "The server can't write to its install directory, so the update can't be applied.",
|
||||
"console.error.no_maintenance": "No maintenance is scheduled.",
|
||||
"console.error.maintenance_closing": "The maintenance is already draining and can no longer be cancelled.",
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"console.error.no_update": "新しいサーバーリリースはありません。",
|
||||
"console.error.already_scheduled": "すでにメンテナンスが予定されています。",
|
||||
"console.error.irreversible_unconfirmed": "このリリースには元に戻せないセーブデータの移行が含まれています。先に移行に関する注意事項を読み、確認してください。",
|
||||
"console.error.invalid_delay": "カウントダウンは 0~1,440 分(24 時間)の範囲で指定してください。",
|
||||
"console.error.invalid_delay": "カウントダウンは 0(すぐに開始)または 5~1,440 分(24 時間)で指定してください。放置中のプレイヤーにも予告が届くようにするためです。",
|
||||
"console.error.install_not_writable": "サーバーのインストール先に書き込めないため、アップデートを適用できません。",
|
||||
"console.error.no_maintenance": "予定されているメンテナンスはありません。",
|
||||
"console.error.maintenance_closing": "すでに処理の終了待ちに入っているため、メンテナンスをキャンセルできません。",
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"console.error.no_update": "새 서버 릴리스가 없습니다.",
|
||||
"console.error.already_scheduled": "이미 점검이 예약되어 있습니다.",
|
||||
"console.error.irreversible_unconfirmed": "이 릴리스에는 되돌릴 수 없는 저장 데이터 마이그레이션이 포함되어 있습니다. 먼저 마이그레이션 안내를 읽고 확인하세요.",
|
||||
"console.error.invalid_delay": "카운트다운은 0~1,440분(24시간) 사이여야 합니다.",
|
||||
"console.error.invalid_delay": "카운트다운은 0(즉시 시작) 또는 5~1,440분(24시간)이어야 합니다. 그래야 대기 중인 플레이어도 안내를 받을 수 있습니다.",
|
||||
"console.error.install_not_writable": "서버 설치 폴더에 쓸 수 없어 업데이트를 적용할 수 없습니다.",
|
||||
"console.error.no_maintenance": "예약된 점검이 없습니다.",
|
||||
"console.error.maintenance_closing": "이미 진행 중인 요청을 마무리하고 있어 점검을 취소할 수 없습니다.",
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"console.error.no_update": "没有可用的新版本。",
|
||||
"console.error.already_scheduled": "已经安排了一次维护。",
|
||||
"console.error.irreversible_unconfirmed": "该版本包含不可回滚的存档迁移,请先阅读迁移说明并勾选确认。",
|
||||
"console.error.invalid_delay": "倒计时需在 0 到 1,440 分钟(24 小时)之间。",
|
||||
"console.error.invalid_delay": "倒计时需为 0(立即开始)或 5 到 1,440 分钟(24 小时),让挂机的玩家也能收到提醒。",
|
||||
"console.error.install_not_writable": "服务端对安装目录没有写权限,无法应用更新。",
|
||||
"console.error.no_maintenance": "当前没有安排维护。",
|
||||
"console.error.maintenance_closing": "维护已进入排空阶段,不能再取消。",
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
"console.error.no_update": "沒有可用的新版本。",
|
||||
"console.error.already_scheduled": "已經安排了一次維護。",
|
||||
"console.error.irreversible_unconfirmed": "該版本包含不可還原的存檔遷移,請先閱讀遷移說明並勾選確認。",
|
||||
"console.error.invalid_delay": "倒數計時需在 0 到 1,440 分鐘(24 小時)之間。",
|
||||
"console.error.invalid_delay": "倒數計時需為 0(立即開始)或 5 到 1,440 分鐘(24 小時),讓掛機的玩家也能收到提醒。",
|
||||
"console.error.install_not_writable": "伺服器沒有安裝目錄的寫入權限,無法套用更新。",
|
||||
"console.error.no_maintenance": "目前沒有安排維護。",
|
||||
"console.error.maintenance_closing": "維護已開始等待進行中的請求完成,無法再取消。",
|
||||
|
||||
@@ -77,7 +77,8 @@ var Document = commonconfig.Document[Config]{
|
||||
{Value: MethodDocker, Label: "Docker", Help: "排空并保存后退出,由宿主机脚本切换到清单指定的镜像。"},
|
||||
{Value: MethodNone, Label: "仅通知", Help: "只检查和展示,不提供应用更新。"},
|
||||
}},
|
||||
{Path: "countdown_minutes", Kind: commonconfig.KindInteger, Label: "默认倒计时(分钟)", Min: countdownMin, Max: countdownMax},
|
||||
{Path: "countdown_minutes", Kind: commonconfig.KindInteger, Label: "默认倒计时(分钟)", Min: countdownMin, Max: countdownMax,
|
||||
Help: "0 表示立即维护;否则至少 5 分钟,挂机玩家的客户端每 3 分钟才查询一次服务器。"},
|
||||
{Path: "maintenance_minutes", Kind: commonconfig.KindInteger, Label: "预计维护时长(分钟)", Min: downtimeMin, Max: downtimeMax},
|
||||
{Path: "webhook_url", Kind: commonconfig.KindString, Label: "Webhook 地址", Format: "url", Advanced: true, Help: "发现新版时向此地址 POST 一次 JSON;留空不发送。"},
|
||||
}},
|
||||
@@ -88,6 +89,9 @@ var Document = commonconfig.Document[Config]{
|
||||
if interval, err := time.ParseDuration(c.CheckInterval); err != nil || interval < 10*time.Minute {
|
||||
problems = append(problems, commonconfig.Problem{Path: "check_interval", Rule: commonconfig.RuleFormat, Message: "检查间隔至少 10m,例如 6h"})
|
||||
}
|
||||
if c.CountdownMinutes > 0 && time.Duration(c.CountdownMinutes)*time.Minute < MinimumCountdown {
|
||||
problems = append(problems, commonconfig.Problem{Path: "countdown_minutes", Rule: commonconfig.RuleRange, Message: "倒计时为 0(立即维护)或至少 5 分钟"})
|
||||
}
|
||||
switch c.Method {
|
||||
case MethodNative, MethodDocker, MethodNone:
|
||||
default:
|
||||
|
||||
@@ -464,8 +464,8 @@ func (s *Service) schedule(component string, delay time.Duration, confirmIrrever
|
||||
return reject("incompatible_schedules", "%s", schedule.Incompatible)
|
||||
case component == ComponentServer && available.Migration.Kind == release.MigrationIrreversible && !confirmIrreversible:
|
||||
return reject(RejectIrreversible, "%s contains a save migration that cannot be rolled back: %s; confirm it explicitly", available.Version, available.Migration.Note.In(i18n.Fallback))
|
||||
case delay < 0 || delay > 24*time.Hour:
|
||||
return reject(RejectInvalidDelay, "the countdown must be between 0 and 24 hours")
|
||||
case delay < 0 || delay > 24*time.Hour || (delay > 0 && delay < MinimumCountdown):
|
||||
return reject(RejectInvalidDelay, "the countdown must be 0 (now) or between 5 minutes and 24 hours")
|
||||
}
|
||||
for _, file := range []string{pendingFile, schedulePendingFile} {
|
||||
if _, err := os.Stat(filepath.Join(directory(s.options.DataDir), file)); err == nil {
|
||||
@@ -739,6 +739,11 @@ func (s *Service) serveControl(ctx context.Context) {
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
// MinimumCountdown is the shortest countdown other than an immediate
|
||||
// maintenance. An idle game client only polls the server every three minutes,
|
||||
// so a shorter warning can reach players after maintenance has begun.
|
||||
const MinimumCountdown = 5 * time.Minute
|
||||
|
||||
// Rejection codes let the console translate why an update request failed.
|
||||
const (
|
||||
RejectNotifyOnly = "notify_only"
|
||||
|
||||
@@ -3,6 +3,7 @@ package updates
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
@@ -126,3 +127,31 @@ func TestRestartDoesNotTrustAnUnsignedOfferSavedInStatus(t *testing.T) {
|
||||
t.Fatal("a status-file edit bypassed the required signed manifest check after restart")
|
||||
}
|
||||
}
|
||||
|
||||
// Idle clients poll every three minutes, so a countdown shorter than five
|
||||
// minutes is refused; five minutes is the shortest one accepted.
|
||||
func TestScheduleRefusesCountdownsTooShortForIdlePlayers(t *testing.T) {
|
||||
config := Default()
|
||||
config.Method = MethodDocker
|
||||
service := New(Options{Config: config, DataDir: t.TempDir(), ServerVersion: "2.36.7+server.0.1.0", Board: notice.NewBoard(nil)})
|
||||
service.status.Available = &Available{Version: "2.36.7+server.0.2.0", Commit: strings.Repeat("a", 40), Migration: release.Migration{Kind: release.MigrationNone}}
|
||||
t.Cleanup(func() { _ = service.Cancel("test cleanup") })
|
||||
for _, delay := range []time.Duration{time.Minute, 4*time.Minute + 59*time.Second} {
|
||||
var rejection *Rejection
|
||||
if err := service.Schedule(delay, false, "owner"); !errors.As(err, &rejection) || rejection.Code != RejectInvalidDelay {
|
||||
t.Fatalf("Schedule(%v) = %v; want an invalid_delay rejection", delay, err)
|
||||
}
|
||||
}
|
||||
if err := service.Schedule(5*time.Minute, false, "owner"); err != nil {
|
||||
t.Fatalf("Schedule(5m) = %v; five minutes must be allowed", err)
|
||||
}
|
||||
// Wait until the countdown starts, which also lets maintenance finish
|
||||
// writing its state before the data directory is removed.
|
||||
deadline := time.Now().Add(3 * time.Second)
|
||||
for state := service.Status(); state.Maintenance == nil || state.Maintenance.Phase != PhaseCountdown; state = service.Status() {
|
||||
if time.Now().After(deadline) {
|
||||
t.Fatalf("a five-minute countdown did not start: %+v", state.Maintenance)
|
||||
}
|
||||
time.Sleep(time.Millisecond)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user