Commit Graph
2 Commits
  • fix(node): stop a departed master's frozen traffic from disabling clients (#6113)
    client_global_traffics rows are keyed by (master_guid, email) and are only
    ever overwritten by a push from that same master. A master that stops
    pushing — decommissioned, reinstalled under a fresh GUID, or detached from
    the node — therefore leaves its last snapshot behind permanently.
    
    depletedClientsCond's cross-panel EXISTS branch matched any such row, so a
    node kept comparing a client's quota against counters frozen weeks earlier.
    Once they exceeded the quota the node disabled the client on every traffic
    poll, and the node -> master enable merge latched that off on the master too,
    where nothing sets it back. The reported symptom is exactly this: a client at
    11 GB of a 24 GB quota, enabled on two nodes, disabled on the third, which
    still held a 27-day-old row from a previous master reporting 30 GB.
    
    Bound both the enforcement predicate and the display overlay to rows a master
    refreshed within globalTrafficFreshWindow. Masters push every 30s, so a live
    master is never affected; a master that is merely unreachable for a while
    keeps enforcing for a full day before its numbers are set aside.
    
    The one-way enable merge that makes such a disable permanent on the master is
    deliberate (12d84c2a, #4917) and is left alone.
  • feat(node-sync): push global client usage to nodes for display and local enforcement
    A client attached to several panels has one aggregated row on each
    master, but a node only ever saw its local share: the node UI
    under-reported usage, and the node kept serving a client whose
    cross-panel total had already exceeded its quota — the master's disable
    push doesn't kill established connections unless the node restarts xray
    itself.
    
    Masters now push their aggregated per-client counters to each node from
    NodeTrafficSyncJob (throttled, scoped to the clients that node hosts).
    The node stores them in the new client_global_traffics side table keyed
    by (masterGuid, email), overwritten on every push so a master-side
    reset propagates, and:
    
    - overlays max(local, pushed) onto UI read paths (slim inbound list,
      inbound detail, clients list, WS stats, per-email lookups). The full
      /panel/api/inbounds/list stays un-overlaid on purpose: it doubles as
      the traffic snapshot masters poll, and overlaying it would corrupt
      every master's delta accounting;
    - trips disableInvalidClients when any master's pushed total exceeds
      the client's quota, so the existing RestartXrayOnClientDisable flow
      disconnects the client locally;
    - clears the side rows on traffic reset, auto-renew, and client
      delete, keeping a renewed quota window clean.
    
    Supersedes #5204, which folded pushed globals into client_traffics and
    compensated with read-back baselines — that double-counted first-sight
    emails and could not work with several masters sharing one node.