[PR #6209] [MERGED] fix(warp): surface update-clock persistence failures #6172

Closed
opened 2026-11-02 04:06:53 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6209
Author: @n0ctal
Created: 8/12/2026
Status: ✅ Merged
Merged: 8/13/2026
Merged by: @MHSanaei

Base: main ← Head: codex/upstream-warp-clock-errors


📝 Commits (2)

  • 6fa0cd4 fix(warp): surface update-clock persistence failures
  • 54aa0ea Merge branch 'main' into codex/upstream-warp-clock-errors

📊 Changes

5 files changed (+122 additions, -8 deletions)

View changed files

📝 internal/web/controller/xray_setting.go (+2 -2)
➕ internal/web/controller/xray_setting_warp_test.go (+71 -0)
📝 internal/web/job/warp_ip_job.go (+11 -3)
➕ internal/web/job/warp_ip_job_test.go (+29 -0)
📝 internal/web/service/setting.go (+9 -3)

📄 Description

Summary

The WARP auto-update clock is written and read without checking the result, so a manual rotation can report success while its schedule was never stored, and the scheduled job cannot distinguish a missing setting from a database failure. This surfaces both.

Why

Two separate problems in the same feature:

The API reports success it did not achieve. After a manual IP change or an interval change, the handler resets warpLastUpdate so the job does not rotate again immediately. The result was discarded, so a failed write produced a success response and a schedule that silently kept the old value.

The job cannot see failures at all. WarpIpJob.Run read the clock with lastUpdate, _ :=. A database failure was indistinguishable from an unset clock, and both landed in the "establish a baseline" branch.

Fixing the second one naively breaks the feature, which is worth spelling out because it is not obvious from the call site: warpLastUpdate is not in defaultValueMap, so on a fresh install getString falls through to key <warpLastUpdate> not in defaultValueMap and returns an error. An early return on that error means the baseline is never written, the error never clears, and scheduled rotation stays dead forever. GetWarpLastUpdate therefore maps "no row" to (0, nil) explicitly and reserves the error for real failures.

Scope

  • internal/web/service/setting.go: GetWarpLastUpdate reads the row directly and treats a missing key as 0, not as an error.
  • internal/web/job/warp_ip_job.go: read failures abort the tick with a log line; write failures are logged, and the restart is still scheduled after an IP change that did happen.
  • internal/web/controller/xray_setting.go: the clock write result is returned to the caller.

GetWarpLastUpdate has exactly one caller besides its declaration, the job itself, so the semantic change is contained.

Validation

  • TestWarpIpJobInitializesMissingLastUpdate runs the job against a fresh database and asserts a non-zero baseline row exists afterwards.
  • TestWarpIntervalReportsClockPersistenceFailure covers the controller path.
  • Mutation-checked: with setting.go reverted, the job test fails with scheduled WARP rotation did not establish its baseline: record not found.
  • go build ./internal/..., go vet, controller/job/service tests, golangci-lint, staticcheck -checks=U1000 (host and GOOS=linux), make gen-check: all clean.

Risk

Deliberate and worth calling out: when the manual changeIp action succeeds but the clock write fails, the API now answers with an error even though the WARP IP has already changed and the Xray restart has already been flagged. The alternative is to keep reporting success and lose the schedule, which is what happens today. The operator should learn that the rotation schedule is not what they think it is.

The external WARP endpoint is not exercised by the tests; the successful-rotation path is unchanged and its behaviour follows from the untouched code.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6209 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 8/12/2026 **Status:** ✅ Merged **Merged:** 8/13/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `codex/upstream-warp-clock-errors` --- ### 📝 Commits (2) - [`6fa0cd4`](https://github.com/MHSanaei/3x-ui/commit/6fa0cd4e8994c69c46bd7e922fc94167728de4ca) fix(warp): surface update-clock persistence failures - [`54aa0ea`](https://github.com/MHSanaei/3x-ui/commit/54aa0ea3364e30b0ac715e6fc1e2bb6756773387) Merge branch 'main' into codex/upstream-warp-clock-errors ### 📊 Changes **5 files changed** (+122 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/controller/xray_setting.go` (+2 -2) ➕ `internal/web/controller/xray_setting_warp_test.go` (+71 -0) 📝 `internal/web/job/warp_ip_job.go` (+11 -3) ➕ `internal/web/job/warp_ip_job_test.go` (+29 -0) 📝 `internal/web/service/setting.go` (+9 -3) </details> ### 📄 Description ## Summary The WARP auto-update clock is written and read without checking the result, so a manual rotation can report success while its schedule was never stored, and the scheduled job cannot distinguish a missing setting from a database failure. This surfaces both. ## Why Two separate problems in the same feature: **The API reports success it did not achieve.** After a manual IP change or an interval change, the handler resets `warpLastUpdate` so the job does not rotate again immediately. The result was discarded, so a failed write produced a success response and a schedule that silently kept the old value. **The job cannot see failures at all.** `WarpIpJob.Run` read the clock with `lastUpdate, _ :=`. A database failure was indistinguishable from an unset clock, and both landed in the "establish a baseline" branch. Fixing the second one naively breaks the feature, which is worth spelling out because it is not obvious from the call site: `warpLastUpdate` is not in `defaultValueMap`, so on a fresh install `getString` falls through to `key <warpLastUpdate> not in defaultValueMap` and returns an error. An early `return` on that error means the baseline is never written, the error never clears, and scheduled rotation stays dead forever. `GetWarpLastUpdate` therefore maps "no row" to `(0, nil)` explicitly and reserves the error for real failures. ## Scope - `internal/web/service/setting.go`: `GetWarpLastUpdate` reads the row directly and treats a missing key as `0`, not as an error. - `internal/web/job/warp_ip_job.go`: read failures abort the tick with a log line; write failures are logged, and the restart is still scheduled after an IP change that did happen. - `internal/web/controller/xray_setting.go`: the clock write result is returned to the caller. `GetWarpLastUpdate` has exactly one caller besides its declaration, the job itself, so the semantic change is contained. ## Validation - `TestWarpIpJobInitializesMissingLastUpdate` runs the job against a fresh database and asserts a non-zero baseline row exists afterwards. - `TestWarpIntervalReportsClockPersistenceFailure` covers the controller path. - Mutation-checked: with `setting.go` reverted, the job test fails with `scheduled WARP rotation did not establish its baseline: record not found`. - `go build ./internal/...`, `go vet`, controller/job/service tests, `golangci-lint`, `staticcheck -checks=U1000` (host and `GOOS=linux`), `make gen-check`: all clean. ## Risk Deliberate and worth calling out: when the manual `changeIp` action succeeds but the clock write fails, the API now answers with an error even though the WARP IP has already changed and the Xray restart has already been flagged. The alternative is to keep reporting success and lose the schedule, which is what happens today. The operator should learn that the rotation schedule is not what they think it is. The external WARP endpoint is not exercised by the tests; the successful-rotation path is unchanged and its behaviour follows from the untouched code. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:06:53 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6172
No description provided.