[GH-ISSUE #5250] [Bug]: Online Client Log Issue #3676

Closed
opened 2026-10-31 20:34:10 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @ArminDeihim on GitHub (Jun 13, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5250

Describe the bug

There is issue with showing Online Clients in the Panel:
The online clients showing on "Clients" page is mismatch with online clients that are showing on "Inbounds" page at the same time. It seems they are not synchronised. For example when the Clients page shows 5 clients online the Inbounts page shows only 3 clients online at that time. The Clients page doesn't refresh quickly enough and it has a log delay that shows a client online long after they have been disconnected.

How to reproduce the problem

1- Check the online total clients reported on "Clients" page and compare that to the online clients that are showing on Inbounds page at same time. You will find that number of total clients on "Clients" page is always higher that clients that are really online online and showing on "Inbounds" page.

Expected behavior

1- Expecting both "Inbounds" and "Clients" page show the same numbers of online clients at same time. In other word that should be synchronised.

Actual behavior

No response

Relevant logs


Screenshots

No response

3x-ui version

3.3.1

Xray-core version

26.6.1

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu 24

Which parts of the panel are affected?

Statistics / traffic counters

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

No — direct access

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @ArminDeihim on GitHub (Jun 13, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5250 ### Describe the bug There is issue with showing Online Clients in the Panel: The online clients showing on "Clients" page is mismatch with online clients that are showing on "Inbounds" page at the same time. It seems they are not synchronised. For example when the Clients page shows 5 clients online the Inbounts page shows only 3 clients online at that time. The Clients page doesn't refresh quickly enough and it has a log delay that shows a client online long after they have been disconnected. ### How to reproduce the problem 1- Check the online total clients reported on "Clients" page and compare that to the online clients that are showing on Inbounds page at same time. You will find that number of total clients on "Clients" page is always higher that clients that are really online online and showing on "Inbounds" page. ### Expected behavior 1- Expecting both "Inbounds" and "Clients" page show the same numbers of online clients at same time. In other word that should be synchronised. ### Actual behavior _No response_ ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.3.1 ### Xray-core version 26.6.1 ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu 24 ### Which parts of the panel are affected? Statistics / traffic counters ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? No — direct access ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:34:10 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jun 13, 2026):

Both behaviors are confirmed in the v3.3.1 source and share a common root cause: the Xray stats API reports user traffic as a single per-email aggregate (user>>>email>>>traffic>>>uplink/downlink) with no per-inbound breakdown. The panel infers which inbound was active by cross-referencing the inbound-level stats (inbound>>>tag>>>traffic>>>uplink/downlink), but that inference has a failure window that produces both symptoms.


How online state is computed

The XrayTrafficJob runs every ~5 s (internal/web/job/xray_traffic_job.go). Each tick it:

  1. Collects per-email traffic deltas (clientTraffics) and per-inbound tag traffic deltas (traffics) from Xray's gRPC stats API.
  2. Adds any email with a non-zero delta to activeEmails.
  3. If the Xray core supports GetUsersStats (the statsUserOnline API, which the running core at Xray 26.6.1 does), it adds idle-but-connected clients — those with an open TCP session but zero bytes moved this poll — to activeEmails as well.
  4. Builds activeInboundTags only from inbound-level tags that carried a non-zero delta this tick (step 1; connection-based clients from step 3 contribute no inbound tag here).
  5. Calls RefreshLocalOnlineClients(activeEmails, activeInboundTags), which records the current timestamp for each email and tag, then prunes anything older than a 20 s grace window (onlineGracePeriodMs = 20000, internal/web/service/inbound_node.go:142).

The Clients page reads the flat onlineClients list — the union of every email within the grace window (internal/web/service/client_paging.go:132). The Inbounds page receives a richer WebSocket payload that includes activeInbounds (a per-GUID map of inbound tags that recently carried bytes). The frontend gates per-inbound online markers behind a check (frontend/src/pages/inbounds/useInbounds.ts:225):

const inboundActive = activeForNode === undefined || \!dbInbound.tag || activeForNode.has(dbInbound.tag);
if (inboundActive && nodeOnline?.has(client.email)) online.push(client.email);

Issue 1 — count divergence

An idle-but-connected client (open session, no bytes in the current 5 s window) is detected by GetUsersStats and added to activeEmails, so their entry in localLastOnline is refreshed every poll while the connection is open. However, their inbound tag only gets refreshed in localInboundLastActive when actual bytes transit that inbound. Once the client has been idle for 20 s, the tag expires from localActiveInbounds, while the email stays current. At that point GetActiveInboundsByGuid() returns an empty (or tag-absent) map, the frontend falls through to activeForNode === undefined → inboundActive = true, but nodeOnline has the email — which is the opposite of the intended scenario. Alternatively, if activeForNode is a non-empty set that simply lacks this inbound's tag, inboundActive = false and the client disappears from all per-inbound views. Either way, the Clients page (email-level, no gating) and the Inbounds page (email + tag gating) can diverge.

The 20 s grace window is intentional headroom to survive polls where a session produces no bytes (internal/web/service/inbound_node.go:137–142), but the window for tags and the window for emails can desynchronize when the connection-API path keeps an email alive after the tag has aged out.

Issue 2 — client shown online on all attached inbounds

The per-inbound gating introduced to address issue #4859 (comment in xray_traffic_job.go lines 102–113) works correctly for clients actively moving bytes: only the inbound tags that saw traffic are included in activeInbounds, so inbounds with no traffic for that client are excluded. The failure mode appears when:

  • activeInboundTags is empty for the panel (no inbound carried traffic in the current tick), or
  • the panel's GUID is absent from activeByGuidRef on the frontend (initial page load before the first REST or WebSocket activeInbounds payload arrives).

In both cases the frontend's fallback activeForNode === undefined evaluates inboundActive = true for every inbound, and the email-level online signal then shows the client as online on all of them.


Underlying constraint

The Xray core does not expose a per-inbound, per-user online signal. GetUsersStats returns (email, []ip) globally, with no inbound attribution. The panel approximates per-inbound presence by correlating email-level and inbound-level traffic deltas, which works when both signals are in the same 20 s window but breaks for idle connections (kept alive by the connection API but no bytes to refresh the tag).


Steps that would help a contributor diagnose further

  1. Confirm whether the mismatch appears while a client is actively transferring data, or only when the client is connected but idle (no traffic visible in Xray's stats panel).
  2. Check the browser console on the Inbounds page for the activeInbounds field in the WebSocket traffic message. If it is an empty object {} or the panel's GUID key is absent while a client shows as online on all inbounds, that confirms the grace-window desync described above.

This reply was generated automatically by the issue-triage assistant; a maintainer may follow up.

<!-- gh-comment-id:4697194531 --> @github-actions[bot] commented on GitHub (Jun 13, 2026): Both behaviors are confirmed in the v3.3.1 source and share a common root cause: the Xray stats API reports user traffic as a single per-email aggregate (`user>>>email>>>traffic>>>uplink/downlink`) with no per-inbound breakdown. The panel infers which inbound was active by cross-referencing the inbound-level stats (`inbound>>>tag>>>traffic>>>uplink/downlink`), but that inference has a failure window that produces both symptoms. --- **How online state is computed** The `XrayTrafficJob` runs every ~5 s (`internal/web/job/xray_traffic_job.go`). Each tick it: 1. Collects per-email traffic deltas (`clientTraffics`) and per-inbound tag traffic deltas (`traffics`) from Xray's gRPC stats API. 2. Adds any email with a non-zero delta to `activeEmails`. 3. If the Xray core supports `GetUsersStats` (the `statsUserOnline` API, which the running core at Xray 26.6.1 does), it adds idle-but-connected clients — those with an open TCP session but zero bytes moved this poll — to `activeEmails` as well. 4. Builds `activeInboundTags` only from inbound-level tags that carried a non-zero delta this tick (step 1; connection-based clients from step 3 contribute **no** inbound tag here). 5. Calls `RefreshLocalOnlineClients(activeEmails, activeInboundTags)`, which records the current timestamp for each email and tag, then prunes anything older than a 20 s grace window (`onlineGracePeriodMs = 20000`, `internal/web/service/inbound_node.go:142`). The Clients page reads the flat `onlineClients` list — the union of every email within the grace window (`internal/web/service/client_paging.go:132`). The Inbounds page receives a richer WebSocket payload that includes `activeInbounds` (a per-GUID map of inbound tags that recently carried bytes). The frontend gates per-inbound online markers behind a check (`frontend/src/pages/inbounds/useInbounds.ts:225`): ```typescript const inboundActive = activeForNode === undefined || \!dbInbound.tag || activeForNode.has(dbInbound.tag); if (inboundActive && nodeOnline?.has(client.email)) online.push(client.email); ``` --- **Issue 1 — count divergence** An idle-but-connected client (open session, no bytes in the current 5 s window) is detected by `GetUsersStats` and added to `activeEmails`, so their entry in `localLastOnline` is refreshed every poll while the connection is open. However, their inbound tag only gets refreshed in `localInboundLastActive` when actual bytes transit that inbound. Once the client has been idle for 20 s, the tag expires from `localActiveInbounds`, while the email stays current. At that point `GetActiveInboundsByGuid()` returns an empty (or tag-absent) map, the frontend falls through to `activeForNode === undefined → inboundActive = true`, but `nodeOnline` has the email — which is the opposite of the intended scenario. Alternatively, if `activeForNode` is a non-empty set that simply lacks this inbound's tag, `inboundActive = false` and the client disappears from all per-inbound views. Either way, the Clients page (email-level, no gating) and the Inbounds page (email + tag gating) can diverge. The 20 s grace window is intentional headroom to survive polls where a session produces no bytes (`internal/web/service/inbound_node.go:137–142`), but the window for tags and the window for emails can desynchronize when the connection-API path keeps an email alive after the tag has aged out. **Issue 2 — client shown online on all attached inbounds** The per-inbound gating introduced to address issue #4859 (comment in `xray_traffic_job.go` lines 102–113) works correctly for clients actively moving bytes: only the inbound tags that saw traffic are included in `activeInbounds`, so inbounds with no traffic for that client are excluded. The failure mode appears when: - `activeInboundTags` is empty for the panel (no inbound carried traffic in the current tick), **or** - the panel's GUID is absent from `activeByGuidRef` on the frontend (initial page load before the first REST or WebSocket `activeInbounds` payload arrives). In both cases the frontend's fallback `activeForNode === undefined` evaluates `inboundActive = true` for every inbound, and the email-level online signal then shows the client as online on all of them. --- **Underlying constraint** The Xray core does not expose a per-inbound, per-user online signal. `GetUsersStats` returns `(email, []ip)` globally, with no inbound attribution. The panel approximates per-inbound presence by correlating email-level and inbound-level traffic deltas, which works when both signals are in the same 20 s window but breaks for idle connections (kept alive by the connection API but no bytes to refresh the tag). --- **Steps that would help a contributor diagnose further** 1. Confirm whether the mismatch appears while a client is actively transferring data, or only when the client is connected but idle (no traffic visible in Xray's stats panel). 2. Check the browser console on the Inbounds page for the `activeInbounds` field in the WebSocket `traffic` message. If it is an empty object `{}` or the panel's GUID key is absent while a client shows as online on all inbounds, that confirms the grace-window desync described above. --- *This reply was generated automatically by the issue-triage assistant; a maintainer may follow up.*
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#3676
No description provided.