[PR #4387] [MERGED] fix: prevent online clients from randomly disappearing from panel UI #5680

Closed
opened 2026-11-02 04:03:16 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/4387
Author: @abdalrahmanx9
Created: 5/14/2026
Status: ✅ Merged
Merged: 5/15/2026
Merged by: @MHSanaei

Base: main ← Head: fix/online-clients-disappearing


📝 Commits (2)

  • e5778b1 fix: prevent online clients from randomly disappearing from panel UI
  • a84c24d fix: extend online client grace period to survive idle poll cycles

📊 Changes

3 files changed (+38 additions, -18 deletions)

View changed files

📝 web/job/node_traffic_sync_job.go (+7 -4)
📝 web/job/xray_traffic_job.go (+11 -4)
📝 web/service/inbound.go (+20 -10)

📄 Description

Summary

  • Fix online clients randomly disappearing from the panel UI even though they are still connected and transmitting traffic
  • Online status is now determined from lastOnline DB timestamps with a 5-second grace period instead of being replaced each cycle with only the current traffic poll active clients
  • Idle-but-connected clients remain visible in the online list across polling windows

Closes #4384

Problem

addClientTraffic() in web/service/inbound.go determined "online" status solely based on whether a client transferred bytes in the current 5-second polling window:

  1. When len(traffics) == 0, ALL online clients were immediately cleared via p.SetOnlineClients(make([]string, 0))
  2. Each cycle called p.SetOnlineClients(onlineClients) with only clients who had Up+Down > 0 in that exact poll — completely replacing the previous list
  3. Clients with an idle TCP connection (no bytes for 5s) or whose Xray counter delta was zero in that window were dropped from the UI

Changes

web/service/inbound.go:

  • Removed p.SetOnlineClients(make([]string, 0)) — online clients are no longer wiped on empty traffic polls
  • Removed p.SetOnlineClients(onlineClients) — addClientTraffic now only handles traffic accounting, not online management
  • Added onlineGracePeriodMs = 5000 constant
  • Added RefreshOnlineClientsFromMap() that determines online clients from lastOnline timestamps with the grace period

web/job/xray_traffic_job.go:

  • After querying lastOnlineMap, calls RefreshOnlineClientsFromMap() to compute online clients from persisted timestamps
  • GetOnlineClients() still merges local + remote node online data for multi-node deployments

web/job/node_traffic_sync_job.go:

  • Same fix applied to the node traffic sync path for consistency

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/4387 **Author:** [@abdalrahmanx9](https://github.com/abdalrahmanx9) **Created:** 5/14/2026 **Status:** ✅ Merged **Merged:** 5/15/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/online-clients-disappearing` --- ### 📝 Commits (2) - [`e5778b1`](https://github.com/MHSanaei/3x-ui/commit/e5778b120c48a297c4a973518fec7b178fbfbfc2) fix: prevent online clients from randomly disappearing from panel UI - [`a84c24d`](https://github.com/MHSanaei/3x-ui/commit/a84c24dbfd77a1c1eb31b0763cd7ca860713f189) fix: extend online client grace period to survive idle poll cycles ### 📊 Changes **3 files changed** (+38 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `web/job/node_traffic_sync_job.go` (+7 -4) 📝 `web/job/xray_traffic_job.go` (+11 -4) 📝 `web/service/inbound.go` (+20 -10) </details> ### 📄 Description ## Summary - Fix online clients randomly disappearing from the panel UI even though they are still connected and transmitting traffic - Online status is now determined from `lastOnline` DB timestamps with a 5-second grace period instead of being replaced each cycle with only the current traffic poll active clients - Idle-but-connected clients remain visible in the online list across polling windows Closes #4384 ## Problem `addClientTraffic()` in `web/service/inbound.go` determined "online" status solely based on whether a client transferred bytes in the current 5-second polling window: 1. When `len(traffics) == 0`, ALL online clients were immediately cleared via `p.SetOnlineClients(make([]string, 0))` 2. Each cycle called `p.SetOnlineClients(onlineClients)` with only clients who had `Up+Down > 0` in that exact poll — completely replacing the previous list 3. Clients with an idle TCP connection (no bytes for 5s) or whose Xray counter delta was zero in that window were dropped from the UI ## Changes **`web/service/inbound.go`:** - Removed `p.SetOnlineClients(make([]string, 0))` — online clients are no longer wiped on empty traffic polls - Removed `p.SetOnlineClients(onlineClients)` — `addClientTraffic` now only handles traffic accounting, not online management - Added `onlineGracePeriodMs = 5000` constant - Added `RefreshOnlineClientsFromMap()` that determines online clients from `lastOnline` timestamps with the grace period **`web/job/xray_traffic_job.go`:** - After querying `lastOnlineMap`, calls `RefreshOnlineClientsFromMap()` to compute online clients from persisted timestamps - `GetOnlineClients()` still merges local + remote node online data for multi-node deployments **`web/job/node_traffic_sync_job.go`:** - Same fix applied to the node traffic sync path for consistency --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:03:16 +07:00
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#5680
No description provided.