mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6870] [Bug]: Random Client Desynchronization Across Multiple Nodes Persists After Update #4561
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#4561
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 @Begamegazon on GitHub (Oct 18, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6870
Describe the bug
I previously reported an issue involving repeated setRemoteTraffic: node X lifecycle lift; marking dirty for re-push log messages and users being automatically disabled and re-enabled approximately every 6 seconds.
The issue was identified as a regression in v3.9.0 related to master-to-node synchronization. After the fix was released, I updated my installation, including the master and nodes, but the problem has not been fully resolved.
I am now experiencing intermittent client desynchronization across multiple nodes. Over time, approximately 2–3 clients out of my total of around 700 users become desynchronized per day.
The affected clients appear randomly across different nodes rather than being limited to a specific node. The issue develops over time, and I have not identified a consistent trigger or a reliable way to reproduce it.
This is particularly concerning because the master and nodes can become inconsistent regarding client information or state, potentially requiring manual investigation and correction.
Environment
Panel: Sanaei X-UI
Deployment: 1 master and 8 nodes
Total clients: Approximately 700
Update status: Updated to the version containing the reported fix
Affected nodes: Multiple nodes, seemingly at random
Frequency: Approximately 2–3 affected clients per day
How to reproduce the problem
Set up a Sanaei X-UI deployment with one master and 8 nodes.
Configure approximately 700 clients across the nodes.
Update the master and all nodes to the version containing the reported synchronization fix.
Run the deployment normally and allow the master and nodes to synchronize over time.
Monitor client synchronization and compare client information and status between the master and the corresponding nodes.
After some time, observe that approximately 2–3 clients per day become desynchronized on randomly affected nodes.
The issue occurs intermittently during normal operation. I have not identified a reliable way to trigger it manually, and the affected clients and nodes appear to vary.
Expected behavior
Client information and status should remain consistent between the master and all nodes after synchronization. The synchronization mechanism should reliably reconcile any differences without leaving clients in a desynchronized state.
Actual behavior
Despite updating to the version containing the fix, client desynchronization continues to occur intermittently. Approximately 2–3 clients per day become desynchronized across different nodes, with no obvious pattern.
Relevant logs
Screenshots
No response
3x-ui version
v3.10.2
Xray-core version
No response
How did you install 3x-ui?
install.sh script
Operating system
ubuntu 20.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?
No response
Before submitting
@github-actions[bot] commented on GitHub (Oct 18, 2026):
I can't confirm a new bug yet. The report doesn't say what is actually different between the master and the node for an affected client, and node sync compares several separate fields. The fix from #6786 (
2ffc694a, "fix(nodes): let a master's push and reconcile converge node inbounds") is in v3.10.0 and v3.10.2 (git tag --contains 2ffc694a), so with every panel on v3.10.2 that specific loop should be gone. Something else may still be wrong, but I need the details below to find it.What the code already does about drift. On each traffic sync, the master treats its own client row as the authority for
enableandexpiryTime. It rewrites the node's copy (internal/web/service/client_locks.go:239,liftClientLifecycleInSettings):After that it marks the node dirty so the reconcile job pushes again (
internal/web/service/inbound_node.go:1461, log linesetRemoteTraffic: node %d lifecycle lift; marking dirty for re-push). So a difference inenableor expiry should fix itself within a sync or two. A desync that lasts points to some other field, or to a push that fails. Without your data I can't tell which.Please reply with:
enable, expiry time, total/used traffic, and whether the client exists at all on the node. This tells me which code path is involved.setRemoteTraffic:, plus any warning or error that names the node:admin,node-sync, ...).Verdict: Insufficient information
Severity: N/A
Confidence: Medium
Root cause: Not established. The report doesn't say which field differs, and the known
enable/expiry loop from #6786 is fixed in the version you run.Same class: Not applicable
Already fixed: The #6786 loop is fixed by
2ffc694a, which is in v3.10.0 and v3.10.2. Other v3.10.x node-sync fixes include2c5fc8e7(an empty snapshot no longer deletes clients),dd956947,6be3c438andf8b72de9. The only commit after v3.10.2 isa8d0700b(token scope for panel updates), which doesn't change sync.Duplicate of: Related: #6786
Evidence:
client_locks.go:239-289(master'senable/expiryTimeoverrides the node's copy);inbound_node.go:1456-1465(marks the node dirty for a re-push);git tag --contains 2ffc694a→ v3.10.0, v3.10.2.Not determined: Which field drifts, and whether a re-push to the node fails or succeeds without applying. Answers 1 and 3 above would settle this.
This reply was generated automatically; a maintainer may follow up.
@Begamegazon commented on GitHub (Oct 18, 2026):
Here is a concrete example of the issue:
The affected client is enabled on the master and across all other nodes, but it is shown as disabled on node 8.
Master: Client is enabled.
Other nodes: Client is enabled.
Node 8: The same client is shown as disabled.
Because the client status differs between the master and node 8, the master repeatedly attempts to synchronize the client's status. The client appears to switch between enabled and disabled on the master every few seconds.
No. The issue does not resolve itself.
If I manually enable the affected client on node 8, it becomes disabled again automatically after a few seconds. The enabled state does not persist.
The only workaround I have found so far is to open the affected node, delete the desynchronized client from that node, and allow the synchronization mechanism to handle it afterward.
This behavior suggests that the node may be retaining or repeatedly restoring an incorrect client state, even after the master attempts to synchronize it.
@github-actions[bot] commented on GitHub (Oct 18, 2026):
Thanks, this narrows it down. Node 8 is disabling the client on its own: its traffic job decides the client is used up or expired, even though the master doesn't. The master then re-enables it and pushes it back, and this repeats. I still can't say which limit node 8 thinks the client has hit. That depends on the values stored in node 8's database, and the two queries below will show them.
What the code shows
Node 8 disables the client on every traffic tick. Every panel, including a node, runs
disableInvalidClients(internal/web/service/inbound_disable.go:80). It disables any enabled client that matches this condition (inbound_disable.go:46-53):This explains why enabling the client by hand on node 8 doesn't stick. The next tick matches the same row and disables it again.
The master's push can't clear the condition that matches. When the master pushes the client to node 8, the node updates only the client's limits and flags (
UpdateClientStat,internal/web/service/inbound_traffic.go:619-636):enable,total,expiry_time,reset*. It does not touchup/down, and it does not touch theclient_global_trafficsrows. So if node 8's localup + downor a pushed global row is overtotal, re-pushing never fixes it.Why deleting the client works. Deleting the client on the node goes through
DelClientStat(inbound_traffic.go:639-650). That deletes theclient_trafficsrow and clearsclient_global_trafficsfor that email. The client then comes back with fresh counters. This supports the idea that node 8's stored counters, not the client's settings, are what's wrong.Why the master keeps switching. The master accepts a node's "disabled" report only when the node's
expiry_timeandtotalmatch its own (nodeDisableIsStale,internal/web/service/inbound_node.go:290-300). Its comment says: "Matching limits mean the node judged the client on the master's own terms: that verdict is genuine and still latches, as #4917 requires." Meanwhile the lift step treats the master's row as the source of truth and re-pushes (client_locks.go:274-278, theninbound_node.go:1461). So if the master and node 8 disagree on usage, the master and node keep overriding each other. That matches the switching you see.What would settle it. On the master, the client's
up + downis the total across all nodes, so node 8's local share should never be larger. If node 8 holds a largerup + down, or a global row over the quota, then a reset or renewal on the master never reached node 8. Which reset path missed it is the actual bug. Please run these while a client is stuck (installsqlite3withapt install sqlite3if needed), replacingCLIENT_EMAIL:reset/ monthly / weekly) enabled? This shows which reset path to check.journalctl -u x-ui --since "2 hours ago" | grep -iE "setRemoteTraffic|reset|node"), and confirmation that node 8 itself runs v3.10.2.Verdict: Insufficient information
Severity: N/A
Confidence: Medium
Root cause: Narrowed but not established. Node 8's own
disableInvalidClients(inbound_disable.go:80) keeps disabling the client, and the master's re-push can't clear that becauseUpdateClientStat(inbound_traffic.go:619) never resetsup/downorclient_global_traffics. Which of the three conditions indepletedClientsCondmatches, and why node 8's stored counters differ from the master's, is unknown.Same class: Not applicable until the matching condition is known
Already fixed: Not applicable. The only commit after v3.10.2 is
a8d0700b(token scope), which doesn't change sync.Duplicate of: Related: #6786, #4917, #6113
Evidence:
inbound_disable.go:46-53(depleted condition, including the global-traffic check);inbound_traffic.go:619-636(a push updates limits and flags, not counters);inbound_traffic.go:639-650(deleting clears both tables, which is why the workaround works);inbound_node.go:290-300(nodeDisableIsStale, the master accepts a node's disable when limits match);client_locks.go:274-278andinbound_node.go:1461(lift and re-push).Not determined: Whether node 8's
up + down,expiry_time, or aclient_global_trafficsrow matches the condition. The two node-8 queries above settle this.This reply was generated automatically; a maintainer may follow up.
@Begamegazon commented on GitHub (Oct 18, 2026):
Here are the database query results for an affected client (
ariana23ranjbar) from node 8, where the client is incorrectly disabled.1.
client_trafficson node 82.
client_global_trafficson node 8The client is disabled on node 8 (
enable = 0), and manually enabling it does not persist. It becomes disabled again after a few seconds.Unfortunately, my master uses PostgreSQL rather than SQLite, so I have not yet retrieved the equivalent database records from the master for comparison.
@github-actions[bot] commented on GitHub (Oct 18, 2026):
Your node-8 numbers rule out what I suggested last time. Node 8's own traffic job cannot have disabled this client. The likely cause is the master side: it accepts a "disabled" report from a node whenever quota and expiry match, even if its own numbers say the client is fine. It then pushes that state back, so the client stays stuck.
Your values against node 8's disable condition (
depletedClientsCond,internal/web/service/inbound_disable.go:46-53):total > 0 AND up + down >= totalexpiry_time > 0 AND expiry_time <= nowg.up + g.down >= total(global row, fresh)So
disableInvalidClients(inbound_disable.go:80) does not select this row, and theenable = 0came from somewhere else. On a node, the other writer ofclient_traffics.enableduring normal sync is the master's inbound push. The master callspanel/api/inbounds/update/:id(internal/web/runtime/remote.go:472), and the node copies the pushed client'senableinto the row throughUpdateClientStat(internal/web/service/inbound.go:2438→inbound_traffic.go:619-636).Why the master keeps the bad state. When node 8 reports
enable = false, the master decides whether to accept it here (internal/web/service/inbound_node.go:290-300):When the limits match, it returns "not stale" before it checks
masterLimitsAllowClient. The merge then disables the master's row (inbound_node.go:1178-1179, and theELSE 0/ELSE falsebranch ofClientTrafficEnableMergeExpr,internal/database/dialect.go:42-58). After that,liftClientLifecycleInSettings(internal/web/service/client_locks.go:274-278) treats the master row as the source of truth and re-pushesenable = falseto the node (inbound_node.go:1461).The comment's assumption is that an
enable = falsewith matching limits must come from the node's depletion job. Your row shows that assumption is false: the limits match, yet no depletion branch can producefalse. Once such afalsereaches node 8, by any route, nothing clears it. That fits what you see:false.DelClientStat(inbound_traffic.go:639-650) removes the row, and the client comes back fresh.Workaround until this is addressed: delete and re-sync the client on the affected node, as you are already doing.
Verdict: Confirmed bug
Severity: High
Confidence: Medium
Root cause:
nodeDisableIsStale,internal/web/service/inbound_node.go:296-298. Whenever a node reportsenable=falsewithexpiry_time/totalequal to the master's, the master accepts it unconditionally, even whenmasterLimitsAllowClient(inbound_node.go:275-286) says the master's limits still allow the client. The latch was introduced in6f7a3052"fix(node): stop stale expiry sync from undoing client extensions (#6228) (#6231)".Same class:
ClientTrafficEnableMergeExpr(internal/database/dialect.go:44-58) encodes the same rule in SQL (it re-enables only when limits differ).liftClientLifecycleInSettings(client_locks.go:276-278) then propagates the latched value back to the node.applyMasterClientLifecycle(inbound_node.go:323-324) copies the latchedmaster.Enableinto the client record.Already fixed: Still present on the default branch. The only commit after v3.10.2 is
a8d0700b(token scope), which doesn't touch sync.Duplicate of: Related: #6786, #6228, #4917
Evidence: Reporter's node-8 row checked against
inbound_disable.go:46-53(no branch matches).inbound_node.go:296-298(limit-match short-circuit),inbound_node.go:1178-1179(master latches the node's false),client_locks.go:274-278+inbound_node.go:1461(re-push of the latched value),inbound_traffic.go:619-636(push writesenableon the node),inbound_traffic.go:639-650(delete clears the row, hence the workaround).Not determined: How the first
enable=falsereached node 8. Candidates are a master push that carriedfalse(an earlier depletion or manual disable on the master, re-enabled later), clock skew around expiry, or a push skipped by the reconcile fingerprint cache (remote.go:499-506). Also undetermined is what flips the master back to enabled every few seconds. The master'sclient_trafficsrow for this email (SELECT email, enable, up, down, total, expiry_time FROM client_traffics WHERE email='ariana23ranjbar';inpsql), plus master log lines containingsetRemoteTrafficfor node 8, would show both.Suggested fix: In
nodeDisableIsStale, consultmasterLimitsAllowClienteven when the limits match. A nodefalsethat the master's own counters, quota and deadline cannot explain should not latch, while a genuine combined-quota or expiry disable still does (#4917). The SQL CASE inClientTrafficEnableMergeExprmust change the same way, or the Go prediction atinbound_node.go:1178and the actual UPDATE will disagree.@MHSanaei: confirmed node-sync bug. A node-reported
enable=falsewith matching limits is latched by the master even when the master's own limits allow the client, which leaves clients stuck disabled on a node.This reply was generated automatically; a maintainer may follow up.
@Begamegazon commented on GitHub (Oct 19, 2026):
Additional Update: Inconsistent Desynchronization Behavior Across Nodes
I would like to provide an additional clarification regarding the issue.
The desynchronization behavior is random and varies across different nodes and clients.
I have observed two different scenarios:
Scenario 1: Client status desynchronization only
The client's traffic usage and expiry time are synchronized correctly between the master and the affected node.
However, the client is incorrectly shown as disabled on the affected node, even though it is enabled on the master and other nodes.
Manually enabling the client on the affected node does not resolve the issue, as it becomes disabled again after a few seconds.
Scenario 2: Client status and data desynchronization
On some other nodes, different affected clients experience desynchronization not only in their enabled/disabled status but also in their traffic usage and expiry time.
In these cases, the client's traffic counters and/or expiry time differ between the master and the affected node, in addition to the enable/disable issue.
These problems occur randomly. The affected clients and nodes vary, and I have not identified a consistent pattern or a reliable way to reproduce the issue.
This suggests that there may be more than one synchronization failure involved, or that the same underlying issue affects different client fields under different circumstances.