mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6595] [MERGED] fix(nodes): stop a restarting panel from reporting itself as down #6368
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6368
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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)
979d7bcfix(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, andnodes/addreads that as unreachable.Why
nodes/addcallsensureReachable→Probe, which doesGET {node}/panel/api/server/status. That endpoint returnsserverService.LastStatus(), i.e. whatever the@every 2sticker last sampled, so a panel that has just restarted answers{"success":true,"msg":"","obj":null}.Probefolds that intoif !envelope.Success || envelope.Obj == nil, producing"remote returned success=false: " + envelope.Msg— andMsgis empty, because the node never saidfalse.The window is much wider than one tick.
GetStatusresolved the public IPv4/IPv6 addresses inline, andresolvePublicIPshelds.muacross every HTTP lookup (3s timeout each, 6 IPv4 + 5 IPv6 services). On a box with no IPv6 route the first sample takes ~15s, andSkipIfStillRunningsuppresses the ticks behind it — soserver/statusservesobj: nullfor 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()— returnsLastStatus()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/statusnow serves this instead of a possibly-null snapshot.resolvePublicIPsdoes its lookups outsides.muand only takes the lock to read the "do I still need this" flags and to store the results;GetStatuskicks 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.Probeseparates "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
Areas affected
How was this tested?
Three new tests in
internal/web/service:TestCurrentStatusSamplesBeforeFirstTick— aServerServicethat the ticker has never run must still answer with a snapshot, cache it asLastStatus, and not resample on the next call.TestStatusSampleDoesNotWaitOnPublicIPLookup— with the lookup services pointed at a handler that blocks, the sample must come back withPublicIP.IPv4still 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. Againstmainthis test fails withLastError = "remote returned success=false: ", which is the reported symptom.Suites run locally (Windows, Go 1.27.1, CGO on):
internal/web/service/panel -run TestUpdateProxyEnvVarsfails on Windows onmaintoo — Windows env var names are case-insensitive, sot.Setenv("https_proxy", …)also setsHTTPS_PROXY. Unrelated to this change.Screenshots / recordings
N/A — no UI change.
Breaking changes
None.
/panel/api/server/statuskeeps its shape; it just stops returningobj: nullwhile the panel is warming up, andPublicIPmay be empty in the first sample or two after a restart instead of blocking the sample until the lookup finishes.Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass. — N/A, no frontend changes🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.