[GH-ISSUE #5436] Bug: ExternalTrafficInformEnable=true stops updating local client_traffics (panel shows 0 for all clients) #3800

Closed
opened 2026-10-31 20:35:03 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @mrnickson-hue on GitHub (Jun 19, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5436

Description

When ExternalTrafficInformEnable is set to true and ExternalTrafficInformURI is 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

  • 3x-ui: v3.3.1
  • Xray: v26.6.1

Steps to Reproduce

  1. Enable ExternalTrafficInformEnable = true in Settings
  2. Set ExternalTrafficInformURI to any valid HTTP endpoint
  3. Connect VPN clients and generate traffic
  4. Observe that traffic counters in the Inbounds panel remain at 0 for all clients

Expected Behavior

ExternalTrafficInformEnable should notify the external service AND also update the local client_traffics table so that the panel continues to show per-client traffic as normal.

Actual Behavior

  • client_traffics.up and client_traffics.down columns are never updated while ExternalTrafficInformEnable=true
  • client_traffics.last_online is still updated correctly (so the gRPC connection to Xray works fine)
  • The dashboard total traffic indicator works (inbound-level stats update correctly)
  • Only per-client traffic counters are broken

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:

=== Snapshot 1 ===
client1|575106513857
client2|360981904082
client3|192443999803

=== Snapshot 2 (65 seconds later) ===
client1|575106513857      ← unchanged
client2|360981904082      ← unchanged
client3|192443999803      ← unchanged

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:

WARNING - POST ExternalTrafficInformURI failed: the server closed connection...
WARNING - POST ExternalTrafficInformURI failed: ...
# (no stats update entries at all)

Xray config is correct — policy.levels.0.statsUserUplink/Downlink: true and stats: {} are properly set. The gRPC stats API connection is established (confirmed via ss -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 local client_traffics table. 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_traffics table.

Environment

  • Ubuntu 24.04 LTS
  • x-ui installed via official install script
  • Single-node setup (not cluster/multi-node)
Originally created by @mrnickson-hue on GitHub (Jun 19, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5436 ## Description When `ExternalTrafficInformEnable` is set to `true` and `ExternalTrafficInformURI` is 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 - 3x-ui: **v3.3.1** - Xray: **v26.6.1** ## Steps to Reproduce 1. Enable `ExternalTrafficInformEnable = true` in Settings 2. Set `ExternalTrafficInformURI` to any valid HTTP endpoint 3. Connect VPN clients and generate traffic 4. Observe that traffic counters in the Inbounds panel remain at 0 for all clients ## Expected Behavior `ExternalTrafficInformEnable` should **notify** the external service AND **also update** the local `client_traffics` table so that the panel continues to show per-client traffic as normal. ## Actual Behavior - `client_traffics.up` and `client_traffics.down` columns are **never updated** while `ExternalTrafficInformEnable=true` - `client_traffics.last_online` **is** still updated correctly (so the gRPC connection to Xray works fine) - The dashboard total traffic indicator **works** (inbound-level stats update correctly) - Only per-client traffic counters are broken ## 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: ``` === Snapshot 1 === client1|575106513857 client2|360981904082 client3|192443999803 === Snapshot 2 (65 seconds later) === client1|575106513857 ← unchanged client2|360981904082 ← unchanged client3|192443999803 ← unchanged ``` 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: ``` WARNING - POST ExternalTrafficInformURI failed: the server closed connection... WARNING - POST ExternalTrafficInformURI failed: ... # (no stats update entries at all) ``` Xray config is correct — `policy.levels.0.statsUserUplink/Downlink: true` and `stats: {}` are properly set. The gRPC stats API connection is established (confirmed via `ss -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 local `client_traffics` table**. 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_traffics` table. ## Environment - Ubuntu 24.04 LTS - x-ui installed via official install script - Single-node setup (not cluster/multi-node)
bsakaguchi 2026-10-31 20:35:03 +07:00
Author
Owner

@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 ExternalTrafficInformEnable is not the cause

In internal/web/job/xray_traffic_job.go, the traffic poll sequence is:

  1. j.xrayService.GetXrayTraffic() — fetches per-inbound and per-user deltas from Xray's gRPC stats API (line 35)
  2. j.inboundService.AddTraffic(traffics, clientTraffics) — writes those deltas to the local DB, including client_traffics.up / .down (line 39)
  3. j.outboundService.AddTraffic(...) — same for outbounds (line 43)
  4. ExternalTrafficInformEnable check → 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=true cannot cause client_traffics.up/.down to stay at 0.

What the symptom pattern actually indicates

  • client_traffics.last_online updating — but up/down staying at 0 — points to the BumpClientsLastOnline() 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 updates last_online without touching up/down.
  • Inbound-level totals updating correctly confirms the Xray gRPC stats API connection is healthy and inbound-level statsInboundUplink/Downlink counters are emitting data.
  • The gap — inbound stats non-zero, user stats zero — is a strong indicator that Xray is not emitting user>>>email>>>traffic>>>uplink/downlink counters, even though inbound counters are present.

In the default config template (internal/web/service/config.json), both statsUserUplink and statsUserDownlink are 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:

  1. The current Xray config template policy section — from the panel under Settings → Xray Config, specifically the policy block. Confirm statsUserUplink: true and statsUserDownlink: true are present in the level used by your inbounds (normally level "0").

  2. Debug log output — add XUI_LOG_LEVEL=debug to /etc/default/x-ui, restart with systemctl restart x-ui, then reproduce the traffic and post the relevant lines from /var/log/x-ui/3xui.log. At debug level, GetXrayTraffic failures are logged; successful polls are silent (which is expected, not evidence of a problem).

  3. Whether disabling ExternalTrafficInformEnable causes client_traffics.up/.down to resume updating — this directly tests whether the correlation is causal or coincidental.

  4. 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.

<!-- gh-comment-id:4751913098 --> @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 `ExternalTrafficInformEnable` is not the cause** In `internal/web/job/xray_traffic_job.go`, the traffic poll sequence is: 1. `j.xrayService.GetXrayTraffic()` — fetches per-inbound and per-user deltas from Xray's gRPC stats API (line 35) 2. `j.inboundService.AddTraffic(traffics, clientTraffics)` — writes those deltas to the local DB, including `client_traffics.up` / `.down` (line 39) 3. `j.outboundService.AddTraffic(...)` — same for outbounds (line 43) 4. `ExternalTrafficInformEnable` check → `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=true` cannot cause `client_traffics.up`/`.down` to stay at 0. **What the symptom pattern actually indicates** - `client_traffics.last_online` updating — but `up`/`down` staying at 0 — points to the `BumpClientsLastOnline()` 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 updates `last_online` without touching `up`/`down`. - Inbound-level totals updating correctly confirms the Xray gRPC stats API connection is healthy and inbound-level `statsInboundUplink`/`Downlink` counters are emitting data. - The gap — inbound stats non-zero, user stats zero — is a strong indicator that Xray is not emitting `user>>>email>>>traffic>>>uplink/downlink` counters, even though inbound counters are present. In the default config template (`internal/web/service/config.json`), both `statsUserUplink` and `statsUserDownlink` are 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:** 1. The current Xray config template policy section — from the panel under Settings → Xray Config, specifically the `policy` block. Confirm `statsUserUplink: true` and `statsUserDownlink: true` are present in the level used by your inbounds (normally level `"0"`). 2. Debug log output — add `XUI_LOG_LEVEL=debug` to `/etc/default/x-ui`, restart with `systemctl restart x-ui`, then reproduce the traffic and post the relevant lines from `/var/log/x-ui/3xui.log`. At debug level, `GetXrayTraffic` failures are logged; successful polls are silent (which is expected, not evidence of a problem). 3. Whether disabling `ExternalTrafficInformEnable` causes `client_traffics.up`/`.down` to resume updating — this directly tests whether the correlation is causal or coincidental. 4. 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.*
Author
Owner

@mrnickson-hue commented on GitHub (Jun 19, 2026):

Update: Root cause found

Thank you for the detailed analysis. You were right — ExternalTrafficInformEnable was not the cause.

The actual root cause was SQLite disk I/O error: no such file or directory errors 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 directory
  • bump last online for connected clients failed: disk I/O error
  • get clients last online failed: disk I/O error

This explains the symptom perfectly: last_online and inbound totals continued updating (read path), while client_traffics.up/down stayed frozen (write path).

Restarting the x-ui service (systemctl restart x-ui) immediately resolved the issue. After restart, client_traffics began 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.

<!-- gh-comment-id:4751969626 --> @mrnickson-hue commented on GitHub (Jun 19, 2026): ## Update: Root cause found Thank you for the detailed analysis. You were right — `ExternalTrafficInformEnable` was not the cause. The actual root cause was **SQLite `disk I/O error: no such file or directory`** errors 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 directory` - `bump last online for connected clients failed: disk I/O error` - `get clients last online failed: disk I/O error` This explains the symptom perfectly: `last_online` and inbound totals continued updating (read path), while `client_traffics.up/down` stayed frozen (write path). Restarting the x-ui service (`systemctl restart x-ui`) immediately resolved the issue. After restart, `client_traffics` began 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.
Author
Owner

@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_traffics barely 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_traffics delta ≈ 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:

  • Per 5-second cycle: large irregular jumps in client_traffics (up to +500 MB in one cycle), with corresponding quiet cycles — clear batch flush pattern
  • 3-minute total: client_traffics delta = 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_traffics barely moving — then received a +21 GB single flush when the connections closed.

Conclusion: This is expected Xray behavior, not a bug. The client_traffics counter 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.

<!-- gh-comment-id:4752764201 --> @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_traffics` barely 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_traffics` delta ≈ 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: - Per 5-second cycle: large irregular jumps in `client_traffics` (up to +500 MB in one cycle), with corresponding quiet cycles — clear batch flush pattern - 3-minute total: `client_traffics` delta = 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_traffics` barely moving — then received a **+21 GB single flush** when the connections closed. **Conclusion:** This is expected Xray behavior, not a bug. The `client_traffics` counter 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.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#3800
No description provided.