mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6734] [MERGED] fix(node): don't delete clients when a node reports an empty snapshot #6434
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#6434
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/6734
Author: @yukh975
Created: 10/5/2026
Status: ✅ Merged
Merged: 10/5/2026
Merged by: @MHSanaei
Base:
main← Head:fix/node-empty-snapshot-client-deletion📝 Commits (4)
4295ee8fix(node): don't delete clients when a node reports an empty snapshot2fc4dc7Merge branch 'main' into fix/node-empty-snapshot-client-deletion23c5107fix(node): keep hub settings on an empty node snapshot; address review0a9e706fix(node): re-push hub clients to a node that reports an empty snapshot📊 Changes
6 files changed (+284 additions, -13 deletions)
View changed files
📝
internal/web/node_contract_test.go(+1 -0)📝
internal/web/runtime/remote.go(+11 -0)📝
internal/web/service/client_sync_orphan_test.go(+21 -12)📝
internal/web/service/inbound_amneziawg_test.go(+3 -0)📝
internal/web/service/inbound_node.go(+43 -1)➕
internal/web/service/node_degraded_snapshot_test.go(+205 -0)📄 Description
Problem
In a hub + managed-nodes setup, the hub reconciles each node by pulling a snapshot and mirroring it into the central DB (
setRemoteTrafficLocked→SyncInbound).SyncInboundmakes an inbound'sclient_inboundslinks match the snapshot exactly: any client missing from the snapshot loses its link. A client left with no links anywhere is then soft-orphaned (markSyncOrphan) and hard-deleted byReapSyncOrphansafter the grace period.The problem: a node that comes back reporting zero clients for an inbound the hub still has clients on is treated as the authoritative truth "every client was removed". But a zero-client snapshot is indistinguishable from a degraded node — one that was just deleted, reset, restarted, or answered before its config finished loading. The existing guard only skips the sweep when
SyncInboundreturns an error; a successful-but-empty snapshot passes straight through.Impact
Removing (or momentarily resetting) a single node cascaded into clients being stripped of their links and reaped across the whole hub — including clients that were still valid and configured on the other nodes. Recovery required restoring the DB from backup.
A subtle tell: TCP traffic by domain keeps working (the name is resolved by the remote node), while the client records quietly disappear and raw DNS/UDP paths break, so it first looks like a DNS problem rather than data loss.
Fix
Treat a zero-client snapshot for an inbound that still has clients attached as non-authoritative: skip the link rebuild and the orphan sweep for that inbound (the same handling a failed
SyncInboundalready gets) and wait for a snapshot that actually carries clients.~21 lines in
setRemoteTrafficLocked, no schema or API change.Tests
node_degraded_snapshot_test.go(new):TestSetRemoteTraffic_EmptySnapshotKeepsClients— an empty snapshot keeps links and does not orphan-mark.TestSetRemoteTraffic_EmptySnapshotSurvivesReap— even a backdatedReapSyncOrphanscan't delete them.TestSetRemoteTraffic_PartialSnapshotStillPrunes— a partial snapshot still prunes + orphan-marks a really-removed client (guard stays narrow).TestSyncOrphanSurvivesMergeUntilGraceElapses/TestSyncOrphanMarkClearedOnReattachupdated to drive removal via a partial snapshot (the authoritative path) instead of an empty one; the soft-orphan / grace / reattach mechanics they cover are unchanged.Verified: both new guard tests fail on
mainwithout the change and pass with it; the full./internal/web/service/suite is green;go build ./...is clean.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.