[PR #5492] [CLOSED] fix(online): gate local inbounds correctly when xray is idle #5900

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5492
Author: @younesvatan78
Created: 6/22/2026
Status: ❌ Closed

Base: main ← Head: fix/online-inbound-gate


📝 Commits (1)

  • 1b35826 fix(online): gate local inbounds correctly when xray is idle

📊 Changes

1 file changed (+10 additions, -4 deletions)

View changed files

📝 internal/web/service/inbound_node.go (+10 -4)

📄 Description

Summary

Multi-inbound clients appeared online on every inbound they were attached to, even when only one of those inbounds had active traffic. The bug surfaced whenever the local xray had no recent traffic (grace window expired between polls, or xray just started).

Root cause

GetActiveInboundsByGuid returned an empty map {} when GetLocalActiveInbounds returned nil (no active inbounds in the grace window). The frontend distinguishes two states by whether the GUID key is present in the map:

Map state Meaning Frontend behaviour
{} — key absent unknown node, hasn't reported yet don't gate (show all clients as active per-inbound)
{guid: []} — empty slice node known, no active inbounds gate all inbounds on that node as inactive

Because the local panel's GUID was missing when idle, activeByGuidRef.current.get(guid) returned undefined, and the undefined === undefined fallback in rollupClients ungated all local inbounds — every client appeared online on all their inbounds regardless of which one carried traffic.

Fix

Resolve the GUID before checking the active list, and always emit {guid: active} (where active may be an empty slice). A missing key still means "unknown remote node — don't gate", which is the correct semantic for nodes that haven't reported yet. Only the local panel is guaranteed to always know its own state.

// before
active := p.GetLocalActiveInbounds()
if len(active) == 0 {
    return map[string][]string{}   // missing key → frontend ungates all inbounds
}
guid := s.panelGuid()
...

// after
guid := s.panelGuid()
...
active := p.GetLocalActiveInbounds()
if active == nil {
    active = []string{}
}
return map[string][]string{guid: active}

Test plan

  • Attach one client to two local inbounds
  • Generate traffic on inbound A only
  • Confirm client shows online on inbound A but not inbound B
  • Wait for the xray grace window to expire (default ~1 min); confirm client shows offline on both inbounds
  • Confirm a client attached only to a remote-node inbound still shows correctly (remote nodes are unaffected — their GUID is only in the map when they have reported)

🔄 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/5492 **Author:** [@younesvatan78](https://github.com/younesvatan78) **Created:** 6/22/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/online-inbound-gate` --- ### 📝 Commits (1) - [`1b35826`](https://github.com/MHSanaei/3x-ui/commit/1b35826e12356674f56bdfb9a1e9cf9ca3843a8b) fix(online): gate local inbounds correctly when xray is idle ### 📊 Changes **1 file changed** (+10 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/inbound_node.go` (+10 -4) </details> ### 📄 Description ## Summary Multi-inbound clients appeared **online on every inbound they were attached to**, even when only one of those inbounds had active traffic. The bug surfaced whenever the local xray had no recent traffic (grace window expired between polls, or xray just started). ## Root cause `GetActiveInboundsByGuid` returned an empty map `{}` when `GetLocalActiveInbounds` returned nil (no active inbounds in the grace window). The frontend distinguishes two states by whether the GUID key is present in the map: | Map state | Meaning | Frontend behaviour | |-----------|---------|-------------------| | `{}` — key absent | unknown node, hasn't reported yet | **don't gate** (show all clients as active per-inbound) | | `{guid: []}` — empty slice | node known, no active inbounds | gate all inbounds on that node as inactive | Because the local panel's GUID was missing when idle, `activeByGuidRef.current.get(guid)` returned `undefined`, and the `undefined === undefined` fallback in `rollupClients` ungated all local inbounds — every client appeared online on all their inbounds regardless of which one carried traffic. ## Fix Resolve the GUID before checking the active list, and always emit `{guid: active}` (where `active` may be an empty slice). A missing key still means "unknown remote node — don't gate", which is the correct semantic for nodes that haven't reported yet. Only the local panel is guaranteed to always know its own state. ```go // before active := p.GetLocalActiveInbounds() if len(active) == 0 { return map[string][]string{} // missing key → frontend ungates all inbounds } guid := s.panelGuid() ... // after guid := s.panelGuid() ... active := p.GetLocalActiveInbounds() if active == nil { active = []string{} } return map[string][]string{guid: active} ``` ## Test plan - [ ] Attach one client to two local inbounds - [ ] Generate traffic on inbound A only - [ ] Confirm client shows online on inbound A but **not** inbound B - [ ] Wait for the xray grace window to expire (default ~1 min); confirm client shows offline on both inbounds - [ ] Confirm a client attached only to a remote-node inbound still shows correctly (remote nodes are unaffected — their GUID is only in the map when they have reported) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:53 +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#5900
No description provided.