mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5436] Bug: ExternalTrafficInformEnable=true stops updating local client_traffics (panel shows 0 for all clients) #3800
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#3800
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 @mrnickson-hue on GitHub (Jun 19, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5436
Description
When
ExternalTrafficInformEnableis set totrueandExternalTrafficInformURIis configured, the per-client traffic counters in the 3x-ui panel stop updating entirely. The panel shows 0 traffic for all clients even though traffic is actively flowing through Xray.Version
Steps to Reproduce
ExternalTrafficInformEnable = truein SettingsExternalTrafficInformURIto any valid HTTP endpointExpected Behavior
ExternalTrafficInformEnableshould notify the external service AND also update the localclient_trafficstable so that the panel continues to show per-client traffic as normal.Actual Behavior
client_traffics.upandclient_traffics.downcolumns are never updated whileExternalTrafficInformEnable=trueclient_traffics.last_onlineis still updated correctly (so the gRPC connection to Xray works fine)Investigation
Confirmed by monitoring the SQLite database directly over 65 seconds while ~6 MB/s of traffic was actively flowing through 54 simultaneous client connections:
Application log (
/var/log/x-ui/3xui.log) shows only the external URI call failures, with zero log entries related to stats collection or local DB updates:Xray config is correct —
policy.levels.0.statsUserUplink/Downlink: trueandstats: {}are properly set. The gRPC stats API connection is established (confirmed viass -tnp— x-u is connected to the metrics port).Root Cause Hypothesis
It appears that when
ExternalTrafficInformEnable=true, x-ui sends traffic deltas to the external URI but does not accumulate them into the localclient_trafficstable. The external URI call seems to replace local storage rather than supplement it.Workaround
We implemented a pull-based workaround: a cron job on each node pulls accumulated totals from the external service every minute and writes them back to the local SQLite
client_trafficstable.Environment
@github-actions[bot] commented on GitHub (Jun 19, 2026):
The root cause hypothesis in the report is not confirmed by the source code, but the symptom pattern itself is real and worth diagnosing.
Why
ExternalTrafficInformEnableis not the causeIn
internal/web/job/xray_traffic_job.go, the traffic poll sequence is:j.xrayService.GetXrayTraffic()— fetches per-inbound and per-user deltas from Xray's gRPC stats API (line 35)j.inboundService.AddTraffic(traffics, clientTraffics)— writes those deltas to the local DB, includingclient_traffics.up/.down(line 39)j.outboundService.AddTraffic(...)— same for outbounds (line 43)ExternalTrafficInformEnablecheck →j.informTrafficToExternalAPI(...)— only marshals and POSTs the already-processed delta slice (line 60)Step 4 runs after the local DB write and only marshals the data as JSON; it does not modify, consume, or replace the slice. A failure of the external POST (connection refused, server closed, etc.) is caught and logged as a Warning; it cannot roll back the already-committed DB transaction. So
ExternalTrafficInformEnable=truecannot causeclient_traffics.up/.downto stay at 0.What the symptom pattern actually indicates
client_traffics.last_onlineupdating — butup/downstaying at 0 — points to theBumpClientsLastOnline()path in the job (line 98). That path fires when Xray's online-stats API reports a client has an active connection but the per-user traffic delta was zero in that poll cycle. It updateslast_onlinewithout touchingup/down.statsInboundUplink/Downlinkcounters are emitting data.user>>>email>>>traffic>>>uplink/downlinkcounters, even though inbound counters are present.In the default config template (
internal/web/service/config.json), bothstatsUserUplinkandstatsUserDownlinkare enabled in policy level"0". If those were missing or applied to a different level number, inbound stats would still work while per-user stats would silently return 0.To identify the actual cause, please provide:
The current Xray config template policy section — from the panel under Settings → Xray Config, specifically the
policyblock. ConfirmstatsUserUplink: trueandstatsUserDownlink: trueare present in the level used by your inbounds (normally level"0").Debug log output — add
XUI_LOG_LEVEL=debugto/etc/default/x-ui, restart withsystemctl restart x-ui, then reproduce the traffic and post the relevant lines from/var/log/x-ui/3xui.log. At debug level,GetXrayTrafficfailures are logged; successful polls are silent (which is expected, not evidence of a problem).Whether disabling
ExternalTrafficInformEnablecausesclient_traffics.up/.downto resume updating — this directly tests whether the correlation is causal or coincidental.Whether the Xray process was restarted around the time the problem appeared (the job's delta tracking requires one skipped poll after each restart, but normal traffic should resume on the second poll).
This reply was generated automatically; a maintainer may follow up.
@mrnickson-hue commented on GitHub (Jun 19, 2026):
Update: Root cause found
Thank you for the detailed analysis. You were right —
ExternalTrafficInformEnablewas not the cause.The actual root cause was SQLite
disk I/O error: no such file or directoryerrors in the x-ui process. These errors occurred intermittently and caused all database write operations to fail, including:add inbound traffic failed: disk I/O error: no such file or directorybump last online for connected clients failed: disk I/O errorget clients last online failed: disk I/O errorThis explains the symptom perfectly:
last_onlineand inbound totals continued updating (read path), whileclient_traffics.up/downstayed frozen (write path).Restarting the x-ui service (
systemctl restart x-ui) immediately resolved the issue. After restart,client_trafficsbegan updating normally.Environment: x-ui 3.3.1, Xray 26.6.1, Ubuntu 22.04
The SQLite WAL state apparently became corrupted without any explicit trigger — no out-of-disk-space condition, no crashed process observed. I'm not sure what triggered this state, but a restart fixed it.
Closing this for now. If the disk I/O errors recur, I'll reopen with more details.
@mrnickson-hue commented on GitHub (Jun 19, 2026):
Additional finding: apparent "traffic not updating" with long-lived connections is normal Xray behavior
After resolving the original SQLite WAL issue, we observed what appeared to be a second separate problem:
client_trafficsbarely updating even with confirmed active traffic (5–6 MB/s on the network interface, CPU at 2.9%).Investigation setup: N1 server, VLESS+XTLS-Vision, one client with 70–80 persistent long-lived TCP connections (continuous large download). Per 5-second job cycle:
client_trafficsdelta ≈ 170–250 KB, while interface RX delta was 24,000–40,000 KB (163× discrepancy).Root cause: Xray batches per-user stats and flushes them when connections close, not continuously. During a 3-minute speedtest (many short connections) on another node, we observed:
client_traffics(up to +500 MB in one cycle), with corresponding quiet cycles — clear batch flush patternclient_trafficsdelta = 3.27 GB, interface total = 3.86 GB — ratio 1.17× ✅With long-lived connections (continuous download), the flush happens when connections eventually close. In our case, the client accumulated a 10+ GB download over several hours with
client_trafficsbarely moving — then received a +21 GB single flush when the connections closed.Conclusion: This is expected Xray behavior, not a bug. The
client_trafficscounter is accurate over the lifetime of a connection, but lags significantly during long-running sessions. Users monitoring the panel in real-time during large sustained transfers will see the counter appear frozen until connections close.