[PR #6595] [MERGED] fix(nodes): stop a restarting panel from reporting itself as down #6368

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6595
Author: @FZ1010
Created: 9/17/2026
Status: ✅ Merged
Merged: 9/18/2026
Merged by: @BlindMaster24

Base: main ← Head: fix/node-probe-cold-status


📝 Commits (1)

  • 979d7bc fix(nodes): stop a restarting panel from reporting itself as down

📊 Changes

6 files changed (+236 additions, -28 deletions)

View changed files

📝 internal/web/controller/server.go (+1 -1)
📝 internal/web/service/node.go (+7 -1)
➕ internal/web/service/node_probe_unsampled_test.go (+48 -0)
📝 internal/web/service/server.go (+86 -26)
➕ internal/web/service/server_cold_status_test.go (+35 -0)
➕ internal/web/service/server_public_ip_async_test.go (+59 -0)

📄 Description

Summary

Adding a node whose panel restarted a few seconds earlier fails with Add node (remote returned success=false: ) — an error with nothing after the colon. The node is healthy; it just has not produced its first status sample yet, and nodes/add reads that as unreachable.

Why

nodes/add calls ensureReachable → Probe, which does GET {node}/panel/api/server/status. That endpoint returns serverService.LastStatus(), i.e. whatever the @every 2s ticker last sampled, so a panel that has just restarted answers {"success":true,"msg":"","obj":null}. Probe folds that into if !envelope.Success || envelope.Obj == nil, producing "remote returned success=false: " + envelope.Msg — and Msg is empty, because the node never said false.

The window is much wider than one tick. GetStatus resolved the public IPv4/IPv6 addresses inline, and resolvePublicIPs held s.mu across every HTTP lookup (3s timeout each, 6 IPv4 + 5 IPv6 services). On a box with no IPv6 route the first sample takes ~15s, and SkipIfStillRunning suppresses the ticks behind it — so server/status serves obj: null for that whole stretch after every restart, and any concurrent reader of the cached IPs blocks on the same mutex.

Measured here as the cold CurrentStatus() call in the new test: 15.75s before, 1.55s after. That also matters for the probe itself, which gives the node 6s.

This is reproducible outside a restart: any automation that changes a setting (which restarts the panel) and then attaches the node hits it, intermittently, depending on how fast that box samples.

Changes

  • ServerService.CurrentStatus() — returns LastStatus() when warm, otherwise takes one sample on demand (double-checked under a dedicated mutex, so a burst during the cold window samples once). /panel/api/server/status now serves this instead of a possibly-null snapshot.
  • resolvePublicIPs does its lookups outside s.mu and only takes the lock to read the "do I still need this" flags and to store the results; GetStatus kicks it off in the background (one in-flight resolve at a time) and reads the cache through a locked accessor. A status sample no longer waits on an external service, and the IP fills in on a later sample.
  • Probe separates "remote said success=false" from "remote returned no status object", so a master meeting an older node gets a message that says something instead of an empty one.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

Three new tests in internal/web/service:

  • TestCurrentStatusSamplesBeforeFirstTick — a ServerService that the ticker has never run must still answer with a snapshot, cache it as LastStatus, and not resample on the next call.
  • TestStatusSampleDoesNotWaitOnPublicIPLookup — with the lookup services pointed at a handler that blocks, the sample must come back with PublicIP.IPv4 still empty, and the address must appear in the cache once the handler is released.
  • TestProbeNamesANodeThatHasNoStatusYet — a node answering {"success":true,"obj":null} must fail with a message naming the missing status. Against main this test fails with LastError = "remote returned success=false: ", which is the reported symptom.

Suites run locally (Windows, Go 1.27.1, CGO on):

go build ./...                                          ok
go test ./internal/web/ ./internal/web/service/ \
        ./internal/web/controller/ ./internal/web/service/tgbot/ -shuffle=on -count=1   ok
go test ./internal/web/service/ -run 'TestCurrentStatus|TestStatusSample|TestProbeNames' -race -count=3 -shuffle=on   ok
gofumpt -l internal/                                    clean

internal/web/service/panel -run TestUpdateProxyEnvVars fails on Windows on main too — Windows env var names are case-insensitive, so t.Setenv("https_proxy", …) also sets HTTPS_PROXY. Unrelated to this change.

Screenshots / recordings

N/A — no UI change.

Breaking changes

None. /panel/api/server/status keeps its shape; it just stops returning obj: null while the panel is warming up, and PublicIP may be empty in the first sample or two after a restart instead of blocking the sample until the lookup finishes.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass. — N/A, no frontend changes
  • I updated the Wiki / README / API docs if user-facing behavior changed. — no endpoint added or renamed
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 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/6595 **Author:** [@FZ1010](https://github.com/FZ1010) **Created:** 9/17/2026 **Status:** ✅ Merged **Merged:** 9/18/2026 **Merged by:** [@BlindMaster24](https://github.com/BlindMaster24) **Base:** `main` ← **Head:** `fix/node-probe-cold-status` --- ### 📝 Commits (1) - [`979d7bc`](https://github.com/MHSanaei/3x-ui/commit/979d7bc1d9642703cbd8f051634c1ffd61913624) fix(nodes): stop a restarting panel from reporting itself as down ### 📊 Changes **6 files changed** (+236 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/controller/server.go` (+1 -1) 📝 `internal/web/service/node.go` (+7 -1) ➕ `internal/web/service/node_probe_unsampled_test.go` (+48 -0) 📝 `internal/web/service/server.go` (+86 -26) ➕ `internal/web/service/server_cold_status_test.go` (+35 -0) ➕ `internal/web/service/server_public_ip_async_test.go` (+59 -0) </details> ### 📄 Description ## Summary Adding a node whose panel restarted a few seconds earlier fails with `Add node (remote returned success=false: )` — an error with nothing after the colon. The node is healthy; it just has not produced its first status sample yet, and `nodes/add` reads that as unreachable. ## Why `nodes/add` calls `ensureReachable` → `Probe`, which does `GET {node}/panel/api/server/status`. That endpoint returns `serverService.LastStatus()`, i.e. whatever the `@every 2s` ticker last sampled, so a panel that has just restarted answers `{"success":true,"msg":"","obj":null}`. `Probe` folds that into `if !envelope.Success || envelope.Obj == nil`, producing `"remote returned success=false: " + envelope.Msg` — and `Msg` is empty, because the node never said `false`. The window is much wider than one tick. `GetStatus` resolved the public IPv4/IPv6 addresses inline, and `resolvePublicIPs` held `s.mu` across every HTTP lookup (3s timeout each, 6 IPv4 + 5 IPv6 services). On a box with no IPv6 route the first sample takes ~15s, and `SkipIfStillRunning` suppresses the ticks behind it — so `server/status` serves `obj: null` for that whole stretch after every restart, and any concurrent reader of the cached IPs blocks on the same mutex. Measured here as the cold `CurrentStatus()` call in the new test: **15.75s before, 1.55s after**. That also matters for the probe itself, which gives the node 6s. This is reproducible outside a restart: any automation that changes a setting (which restarts the panel) and then attaches the node hits it, intermittently, depending on how fast that box samples. ### Changes - `ServerService.CurrentStatus()` — returns `LastStatus()` when warm, otherwise takes one sample on demand (double-checked under a dedicated mutex, so a burst during the cold window samples once). `/panel/api/server/status` now serves this instead of a possibly-null snapshot. - `resolvePublicIPs` does its lookups **outside** `s.mu` and only takes the lock to read the "do I still need this" flags and to store the results; `GetStatus` kicks it off in the background (one in-flight resolve at a time) and reads the cache through a locked accessor. A status sample no longer waits on an external service, and the IP fills in on a later sample. - `Probe` separates "remote said success=false" from "remote returned no status object", so a master meeting an older node gets a message that says something instead of an empty one. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [ ] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [ ] Xray config generation - [ ] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [x] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? Three new tests in `internal/web/service`: - `TestCurrentStatusSamplesBeforeFirstTick` — a `ServerService` that the ticker has never run must still answer with a snapshot, cache it as `LastStatus`, and not resample on the next call. - `TestStatusSampleDoesNotWaitOnPublicIPLookup` — with the lookup services pointed at a handler that blocks, the sample must come back with `PublicIP.IPv4` still empty, and the address must appear in the cache once the handler is released. - `TestProbeNamesANodeThatHasNoStatusYet` — a node answering `{"success":true,"obj":null}` must fail with a message naming the missing status. Against `main` this test fails with `LastError = "remote returned success=false: "`, which is the reported symptom. Suites run locally (Windows, Go 1.27.1, CGO on): ``` go build ./... ok go test ./internal/web/ ./internal/web/service/ \ ./internal/web/controller/ ./internal/web/service/tgbot/ -shuffle=on -count=1 ok go test ./internal/web/service/ -run 'TestCurrentStatus|TestStatusSample|TestProbeNames' -race -count=3 -shuffle=on ok gofumpt -l internal/ clean ``` `internal/web/service/panel -run TestUpdateProxyEnvVars` fails on Windows on `main` too — Windows env var names are case-insensitive, so `t.Setenv("https_proxy", …)` also sets `HTTPS_PROXY`. Unrelated to this change. ## Screenshots / recordings N/A — no UI change. ## Breaking changes None. `/panel/api/server/status` keeps its shape; it just stops returning `obj: null` while the panel is warming up, and `PublicIP` may be empty in the first sample or two after a restart instead of blocking the sample until the lookup finishes. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [ ] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. — N/A, no frontend changes - [x] I updated the Wiki / README / API docs if user-facing behavior changed. — no endpoint added or renamed - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:08:16 +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#6368
No description provided.