mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6749] [Bug]: Node Sync may delete and recreate an existing node inbound, causing client traffic history to reset to 0 #4498
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#4498
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?
Originally created by @hoseyny6223-netizen on GitHub (Oct 6, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6749
Describe the bug
Bug: Node Sync may delete and recreate an existing node inbound, causing client traffic history to reset to 0
Environment
3cd4bf5)2kharejSummary
We observed a serious Node Sync issue where an existing Node inbound appears to be deleted from the Master database and later recreated/adopted as a new inbound.
The affected inbound was:
The Node-side inbound itself was not recreated or deleted. It remained the same
proxy/2053inbound on the Node.Later, the Master contained:
Inbound
20no longer exists.Because PostgreSQL generated a new inbound ID (
24), this does not appear to be a normal update/edit of inbound20.Observed traffic behavior
The most important symptom is that actual Xray/Node traffic was NOT lost.
The Node still had real cumulative traffic for the clients.
The inbound-level traffic on the Master was also still present and showed approximately 499+ GB.
However, several affected clients had their Master
client_trafficsreset to:while the Node still reported substantial traffic.
Examples:
Other affected clients showed the same pattern.
This means the actual Xray traffic counters were not reset; the problem appears to be the Master-side client traffic history/accounting lifecycle.
Database evidence
The Master database currently contains:
Inbound
20is gone.The PostgreSQL sequence is:
There are no custom PostgreSQL triggers on:
inboundsclient_inboundsclientsclient_trafficsnode_client_trafficsThe affected
client_trafficsrows are newer rows with0/0, while some unaffected clients still have older traffic rows with their historical values.Relevant Node Sync log
Around the incident there was also:
We do NOT assume that this specific failed request directly caused the deletion, because the v3.9.0 code returns from
FetchTrafficSnapshot()when the fetch fails.The concern is instead a possible Node Sync race/inconsistent snapshot during the inbound reconciliation/traffic-sync lifecycle.
Why we suspect Node Sync
In
internal/web/service/inbound_node.go,SetRemoteTraffic()contains logic that removes a central inbound when:The code logs:
and then removes the central inbound and can remove associated
client_trafficshistory.If the inbound appears again in a subsequent Node snapshot, the Master can create/adopt it again.
This would explain the observed lifecycle:
We cannot prove from historical DB data exactly why the inbound tag was missing from the snapshot at that moment, because the historical snapshot itself was not persisted.
Additional observation
We repeated the bulk operation that initially appeared suspicious: adding the same Node inbound to multiple clients simultaneously.
The second test did not reproduce the traffic reset.
Therefore we currently do not believe that simply bulk-attaching an inbound to multiple clients is sufficient to trigger the problem.
It may instead interact with Node Sync /
ConfigDirty/ reconciliation timing.Expected behavior
A temporary incomplete or inconsistent Node snapshot should not delete an existing Master inbound and its client traffic history.
If the Node is temporarily unavailable, restarting, reloading Xray, reconciling configuration, or returning an incomplete snapshot, the Master should preserve the existing inbound and its traffic history until the Node state is positively confirmed.
In particular, a transient missing inbound should not result in:
Actual behavior
An existing Node inbound appears to have gone through:
with client-level Master traffic becoming
0/0for multiple affected clients while Node/Xray traffic remained intact.Potential impact
This is particularly serious for clients with finite traffic quotas.
The Master uses client traffic accounting for quota enforcement and disabling depleted clients.
If historical traffic is replaced by
0/0, a client that has already consumed a large amount of traffic may temporarily appear to have unused quota.For example:
This can potentially affect quota enforcement and client enable/disable state.
Request
Please investigate whether the Node Sync /
SetRemoteTraffic()inbound stale-removal logic can incorrectly remove an existing Node inbound when a snapshot is temporarily incomplete or inconsistent.In particular:
FetchTrafficSnapshot()ever return a successful but incomplete inbound list?ReconcileNode()/ConfigDirty/ Xray reload timing produce a snapshot where an existing inbound is temporarily missing?SetRemoteTraffic()delete the central inbound too aggressively?client_trafficshistory that should be preserved?origin_node_guid+ port + protocol/listen be preserved/adopted instead of being deleted/recreated?The issue was observed on the latest stable release:
All domains, tokens, UUIDs and other sensitive identifiers have been redacted.
How to reproduce the problem
The issue could not be reproduced deterministically, but the following sequence reproduces the conditions under which the problem occurred:
Set up a Sanaei v3.9.0 Master and Node, both running Xray 26.9.30, with PostgreSQL on the Master.
Create a Node inbound on the Master and synchronize/deploy it to the Node.
Attach multiple existing clients, which already have traffic history, to this Node inbound.
Allow the clients to generate traffic and confirm that:
Allow the normal Node Traffic Sync / reconciliation process to run.
During the affected incident, the original Master inbound (ID 20) disappeared from the Master database, even though the corresponding inbound on the Node was not recreated or removed.
After a subsequent synchronization, the same Node inbound appeared again on the Master with a new inbound ID (ID 24).
After this lifecycle, multiple affected clients had their Master-side
client_trafficsreset to0 / 0, while the Node still reported their actual cumulative traffic.Repeating the bulk client-to-inbound attachment operation alone did not reproduce the issue consistently. This suggests that the problem is timing-dependent and related to Node Traffic Sync / reconciliation or a transient/incomplete Node snapshot.
The issue appears to require a specific synchronization/reconciliation timing condition rather than being triggered by the client attachment operation alone.
Expected behavior
No response
Actual behavior
No response
Relevant logs
Screenshots
No response
3x-ui version
3.9.0
Xray-core version
26.9.30
How did you install 3x-ui?
install.sh script
Operating system
ubuntu 24.04
Which parts of the panel are affected?
No response
Browser (only if it is a UI bug)
No response
Is the panel behind a reverse proxy or CDN?
None
Before submitting
@github-actions[bot] commented on GitHub (Oct 6, 2026):
The
0 / 0part is a real bug, and it is still in the code on the default branch. WhenSetRemoteTrafficreplaces a node inbound with a new central row, it deletes the old inbound'sclient_trafficsrows. On the next sync it recreates them at zero, and it moves the node baseline up to the node's current counters. The history is then gone for good, and only traffic used after that point gets counted. Your numbers fit this exactly. What I could not pin down is why the snapshot's tag did not match inbound20. That is what the log line requested at the end would show.@MHSanaei: a confirmed bug that resets client quota accounting on node inbounds.
What the code does
Everything below is in
internal/web/service/inbound_node.go,SetRemoteTraffic.existingEmails(the set of emails that already have aclient_trafficsrow) is computed once, before the transaction opens (L640-655).tagToCentral(the stored tag or itsn2-prefix-flipped form, L542-553), the code looks for an alias. It only accepts one that matches exactly on origin GUID, port, protocol and listen (L701-704): If nothing matches, it creates a new central inbound (L758-786). The new inbound'sUp/Downcome from the snapshot (L778-779). That would explain why your inbound-level ~499 GB survived on ID24.snapTags. The guard at L874 only protects a completely empty snapshot. A non-empty snapshot that lacks this one tag goes through. The sweep deletes the per-email rows unless the email is also attached to another inbound (L920-935), which matches your note that some clients kept their history:existingEmailsfrom step 1 still lists those emails. No row gets created, and theUPDATE ... WHERE email = ?statements hit nothing.24no longer counts as a new inbound. The code then takes the zero-seed branch (L998-1001) and resets the baseline to the node's totals (L1025): The client row stays at0/0while the node keeps reporting its full totals. This matchesBaba,Hexa_418825and the others.Your two-tick theory (missing from one snapshot, back in the next) would not give
0/0. In that case the next tick creates the new inbound as new, and the rows get seeded with the node's counters (L999-1000). The0/0result points to the single-tick replace above: the snapshot did report the inbound, under a tag that matched neither inbound20's tag nor an alias.A likely reason the alias check fails: a node inbound created on the master starts with an empty
OriginNodeGuid.inbound.go:218only fills it in for local inbounds (ib.NodeID == nil). The value is otherwise only backfilled at L843-845, after a tag match succeeds. So an inbound that loses its tag match has no GUID-based fallback. This is an inference; I have not confirmed it for your data.On your questions: (3) yes, the sweep (L865-946) deletes on a single non-empty snapshot. (4) yes, as shown above. (6) the alias path (L695-718, added in
bb29b6af) is meant to do exactly this, but its strict equality onOriginNodeGuid/listen can miss.The connection-refused log line is unrelated to the deletion, as you suspected.
Suggested fix: When the sweep removes an inbound whose emails the same snapshot still reports under a newly adopted inbound, move the
client_trafficsrows and baselines over instead of deleting them. Otherwise, refreshexistingEmailsafter the sweep so the rows are seeded from the node's counters. Separately, the alias check could fall back to node + port + protocol + listen when the centralOriginNodeGuidis empty.One thing that would settle the open point
Please run this on the master and paste the matching lines as text. They contain inbound
20's old tag:Please also paste the
tagof theproxy/2053inbound as the node's own panel shows it (Inbounds -> the inbound's JSON).This reply was generated automatically; a maintainer may follow up.