[GH-ISSUE #5893] [Bug]: [LIMIT_IP] Stale IP stays "online" and re-triggers ban for minutes after real TCP connection is already closed #4086

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

Originally created by @yapay389-a11y on GitHub (Jul 10, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5893

Describe the bug

With a client's IP Limit set to 1 and Xray policy connIdle set to 60 (level 0), when that client's underlying connection drops (mobile network switch, wifi/data toggle, weak signal) without a clean TCP close, the panel keeps logging [LIMIT_IP] ... Disconnecting OLD IP for the same address every ~10 seconds, far longer than connIdle should allow. In production (200 clients) this sometimes continues for 15+ minutes with 100+ repeated log lines for a single stale IP, even though the actual TCP connection is already fully closed at the kernel level (confirmed with ss -tnp, which shows nothing at all for that IP while the panel keeps reporting it as online).

Measured worst cases from /var/log/x-ui/3xipl.log:

  • 1000 seconds, 101 repeated [LIMIT_IP] hits for the same (email, IP) pair
  • 890s / 90 hits
  • 740s / 75 hits
  • 380s / 39 hits
  • 270s / 28 hits

Also tried lowering kernel tcp_orphan_retries=1 and tcp_fin_timeout=15 — no effect, which rules out a kernel-level TCP issue and points to the panel/xray-core online-IP tracking (GetOnlineUsers / statsUserOnline / OnlineMap) not clearing the IP entry when the connection actually closes.

Restarting Xray (x-ui restart) clears the stale entries immediately, but the same pattern reoccurs on the very next connection drop for a different client, so restarting is not a real fix — it just resets the state temporarily.

This makes IP-limit-based Fail2ban enforcement effectively unusable for a mobile-heavy customer base: legitimate customers who switch networks trigger dozens of false [LIMIT_IP] events per switch, sometimes lasting 15+ minutes, forcing fail2ban maxretry to be set unreasonably high (100+) just to avoid banning legitimate customers — which in turn defeats the purpose of the IP limit feature.

How to reproduce the problem

  1. Set a client's IP Limit to 1 in the panel
  2. Set Xray policy connIdle to 60 (level 0)
  3. Connect from device A (e.g. mobile app), then let the underlying connection die abruptly without a clean TCP close (toggle airplane mode, or switch from wifi to mobile data), then reconnect with the same client from device B
  4. Watch /var/log/x-ui/3xipl.log — the same OLD IP keeps getting logged with [LIMIT_IP] every ~10 seconds, far past connIdle
  5. Confirm with ss -tnp | grep <old_ip> at the same time — the real TCP connection is already fully gone (no ESTAB, no LAST-ACK, nothing), yet the panel keeps reporting it

Expected behavior

I expected the panel to stop treating the OLD IP as online/live within roughly connIdle (60s) plus one scan interval (10s), i.e. under ~70-80 seconds, once the real TCP connection is closed. Instead the same (email, IP) pair keeps re-triggering [LIMIT_IP] every 10 seconds for minutes, up to 1000 seconds (101 repeated hits) observed in production, long after the underlying connection is confirmed gone at the kernel level.

Actual behavior

No response

Relevant logs


Screenshots

No response

3x-ui version

3.4.2

Xray-core version

26.6.27

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu 24.04

Which parts of the panel are affected?

Backend (API endpoints, login, settings)

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

None

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 @yapay389-a11y on GitHub (Jul 10, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5893 ### Describe the bug With a client's IP Limit set to 1 and Xray policy connIdle set to 60 (level 0), when that client's underlying connection drops (mobile network switch, wifi/data toggle, weak signal) without a clean TCP close, the panel keeps logging [LIMIT_IP] ... Disconnecting OLD IP for the same address every ~10 seconds, far longer than connIdle should allow. In production (200 clients) this sometimes continues for 15+ minutes with 100+ repeated log lines for a single stale IP, even though the actual TCP connection is already fully closed at the kernel level (confirmed with `ss -tnp`, which shows nothing at all for that IP while the panel keeps reporting it as online). Measured worst cases from /var/log/x-ui/3xipl.log: - 1000 seconds, 101 repeated [LIMIT_IP] hits for the same (email, IP) pair - 890s / 90 hits - 740s / 75 hits - 380s / 39 hits - 270s / 28 hits Also tried lowering kernel tcp_orphan_retries=1 and tcp_fin_timeout=15 — no effect, which rules out a kernel-level TCP issue and points to the panel/xray-core online-IP tracking (GetOnlineUsers / statsUserOnline / OnlineMap) not clearing the IP entry when the connection actually closes. Restarting Xray (x-ui restart) clears the stale entries immediately, but the same pattern reoccurs on the very next connection drop for a different client, so restarting is not a real fix — it just resets the state temporarily. This makes IP-limit-based Fail2ban enforcement effectively unusable for a mobile-heavy customer base: legitimate customers who switch networks trigger dozens of false [LIMIT_IP] events per switch, sometimes lasting 15+ minutes, forcing fail2ban maxretry to be set unreasonably high (100+) just to avoid banning legitimate customers — which in turn defeats the purpose of the IP limit feature. ### How to reproduce the problem 1. Set a client's IP Limit to 1 in the panel 2. Set Xray policy connIdle to 60 (level 0) 3. Connect from device A (e.g. mobile app), then let the underlying connection die abruptly without a clean TCP close (toggle airplane mode, or switch from wifi to mobile data), then reconnect with the same client from device B 4. Watch /var/log/x-ui/3xipl.log — the same OLD IP keeps getting logged with [LIMIT_IP] every ~10 seconds, far past connIdle 5. Confirm with `ss -tnp | grep <old_ip>` at the same time — the real TCP connection is already fully gone (no ESTAB, no LAST-ACK, nothing), yet the panel keeps reporting it ### Expected behavior I expected the panel to stop treating the OLD IP as online/live within roughly connIdle (60s) plus one scan interval (10s), i.e. under ~70-80 seconds, once the real TCP connection is closed. Instead the same (email, IP) pair keeps re-triggering [LIMIT_IP] every 10 seconds for minutes, up to 1000 seconds (101 repeated hits) observed in production, long after the underlying connection is confirmed gone at the kernel level. ### Actual behavior _No response_ ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.4.2 ### Xray-core version 26.6.27 ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu 24.04 ### Which parts of the panel are affected? Backend (API endpoints, login, settings) ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? None ### 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:37:04 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jul 10, 2026):

Your own diagnosis is on the right track, and the source confirms exactly where the gap is.

check_client_ip_job (internal/web/job/check_client_ip_job.go) runs every 10 seconds (cadenceClientIPScan = "@every 10s", internal/web/web.go:291,336), matching your observed repeat interval — and your worst case (~1000s / 101 hits) is almost exactly 100 × 10s.

Each run pulls online users from Xray-core's StatsService.GetUsersStats RPC (internal/xray/api.go:711-742, via XrayService.GetOnlineUsers, internal/web/service/xray.go:833-861), backed by the statsUserOnline policy the panel force-enables on every policy level (ensureStatsPolicy, internal/web/service/xray.go:667-710 — note this function never touches connIdle itself). That RPC does return a LastSeen unix timestamp per IP (internal/xray/api.go:694-699: "the unix time (seconds) the core last dispatched a link from it"), but nothing in check_client_ip_job.go ever compares it against connIdle or against "now" to decide liveness:

  • Run() calls processObserved(observed, enforce, true) (line 68) — the trailing true is observedAreLive, hardcoded for every API-sourced observation.
  • In mergeClientIps (lines 391-408), newAlwaysLive skips the job's only staleness cutoff (ipStaleAfterSeconds, 30 minutes, line 42) for these entries entirely.
  • In partitionLiveIps (lines 420-438), an IP counts as "live" once observedThisScan[ip] is true (line 429) — i.e. "Xray listed it this scan" — regardless of how old that same entry's LastSeen is.

So the job's liveness signal reduces to "did GetUsersStats still include this IP," full stop. selectIpsToBan (lines 410-418) then sorts live IPs by that timestamp and evicts the oldest beyond the limit, which is why the same stale IP — always the oldest — gets re-picked every scan and logged via the load-bearing [LIMIT_IP] ... Disconnecting OLD IP line (line 530).

One more relevant data point: every one of those hits also runs RemoveUser then AddUser for that client against the live config (disconnectClientTemporarily, lines 606 and 616) — the job is already actively trying to force-drop the stale connection every 10 seconds, and it still reappears on the next scan. Combined with your own elimination of kernel-level causes (empty ss -tnp, no effect from tcp_orphan_retries/tcp_fin_timeout), this points at Xray-core's own online-IP bookkeeping — the panel's code already refers to it by name, OnlineMap.AddIP (comment at lines 99-100) — retaining the entry independently of both the real socket and of the user being removed/re-added via the API. That part of the mechanism lives inside the github.com/xtls/xray-core dependency (pinned in go.mod at v1.260327.1-0.20260627131803-45cf2898ab12), not in this repository, so I can't cite an exact upstream line, but your tests already rule out the alternatives.

Severity: High
Category: Reliability

Why this matters: as you describe, this makes IP-limit-based fail2ban enforcement unreliable for any mobile-heavy client base — operators are forced to raise maxretry to absurd values to avoid banning legitimate customers, which defeats the feature's actual purpose (detecting concurrent/shared-credential usage). It also causes needless RemoveUser/AddUser churn against the running Xray config on every repeated hit.

Recommendation: bound the API-sourced liveness check locally instead of trusting "still listed" indefinitely — compare each entry's LastSeen (already fetched, currently unused for this) against now, and stop treating an IP as live once that gap exceeds connIdle plus a small buffer (e.g. one scan interval). That caps the worst case at roughly connIdle + 10s regardless of how long Xray's own bookkeeping lags, matching the "~70-80s" you expected. Since connIdle is per policy level and currently only written into the generated config (never read back by the job), this would need a way to read the effective value back, or fall back to Xray's documented default of 300s (the panel's own connIdleDesc string, internal/web/translation/en-US.json:1641). Separately, it may be worth filing this upstream against github.com/xtls/xray-core — specifically why OnlineMap isn't cleared by the panel's RemoveUser/AddUser cycle.

Example:

// internal/web/job/check_client_ip_job.go — partitionLiveIps
if observedThisScan[ip] || now-ts < 120 {
    live = append(live, entry)
}

observedThisScan[ip] alone is sufficient for "live" here — there is no check against that entry's own LastSeen/connIdle anywhere in this path.

Confidence: high for the 3x-ui-side mechanism above (traced end-to-end in the current source, including exact log format and cadence match). Medium for the precise upstream cause of why Xray-core keeps the entry — that lives in xray-core, outside this repository, and is inferred from your kernel-level elimination rather than confirmed against its source.

@MHSanaei

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4934576598 --> @github-actions[bot] commented on GitHub (Jul 10, 2026): Your own diagnosis is on the right track, and the source confirms exactly where the gap is. `check_client_ip_job` (`internal/web/job/check_client_ip_job.go`) runs every 10 seconds (`cadenceClientIPScan = "@every 10s"`, `internal/web/web.go:291,336`), matching your observed repeat interval — and your worst case (~1000s / 101 hits) is almost exactly 100 × 10s. Each run pulls online users from Xray-core's `StatsService.GetUsersStats` RPC (`internal/xray/api.go:711-742`, via `XrayService.GetOnlineUsers`, `internal/web/service/xray.go:833-861`), backed by the `statsUserOnline` policy the panel force-enables on every policy level (`ensureStatsPolicy`, `internal/web/service/xray.go:667-710` — note this function never touches `connIdle` itself). That RPC does return a `LastSeen` unix timestamp per IP (`internal/xray/api.go:694-699`: "the unix time (seconds) the core last dispatched a link from it"), but nothing in `check_client_ip_job.go` ever compares it against `connIdle` or against "now" to decide liveness: - `Run()` calls `processObserved(observed, enforce, true)` (line 68) — the trailing `true` is `observedAreLive`, hardcoded for every API-sourced observation. - In `mergeClientIps` (lines 391-408), `newAlwaysLive` skips the job's only staleness cutoff (`ipStaleAfterSeconds`, 30 minutes, line 42) for these entries entirely. - In `partitionLiveIps` (lines 420-438), an IP counts as "live" once `observedThisScan[ip]` is true (line 429) — i.e. "Xray listed it this scan" — regardless of how old that same entry's `LastSeen` is. So the job's liveness signal reduces to "did `GetUsersStats` still include this IP," full stop. `selectIpsToBan` (lines 410-418) then sorts live IPs by that timestamp and evicts the oldest beyond the limit, which is why the same stale IP — always the oldest — gets re-picked every scan and logged via the load-bearing `[LIMIT_IP] ... Disconnecting OLD IP` line (line 530). One more relevant data point: every one of those hits also runs `RemoveUser` then `AddUser` for that client against the live config (`disconnectClientTemporarily`, lines 606 and 616) — the job is already actively trying to force-drop the stale connection every 10 seconds, and it still reappears on the next scan. Combined with your own elimination of kernel-level causes (empty `ss -tnp`, no effect from `tcp_orphan_retries`/`tcp_fin_timeout`), this points at Xray-core's own online-IP bookkeeping — the panel's code already refers to it by name, `OnlineMap.AddIP` (comment at lines 99-100) — retaining the entry independently of both the real socket and of the user being removed/re-added via the API. That part of the mechanism lives inside the `github.com/xtls/xray-core` dependency (pinned in `go.mod` at `v1.260327.1-0.20260627131803-45cf2898ab12`), not in this repository, so I can't cite an exact upstream line, but your tests already rule out the alternatives. Severity: High Category: Reliability Why this matters: as you describe, this makes IP-limit-based fail2ban enforcement unreliable for any mobile-heavy client base — operators are forced to raise `maxretry` to absurd values to avoid banning legitimate customers, which defeats the feature's actual purpose (detecting concurrent/shared-credential usage). It also causes needless `RemoveUser`/`AddUser` churn against the running Xray config on every repeated hit. Recommendation: bound the API-sourced liveness check locally instead of trusting "still listed" indefinitely — compare each entry's `LastSeen` (already fetched, currently unused for this) against `now`, and stop treating an IP as live once that gap exceeds `connIdle` plus a small buffer (e.g. one scan interval). That caps the worst case at roughly `connIdle` + 10s regardless of how long Xray's own bookkeeping lags, matching the "~70-80s" you expected. Since `connIdle` is per policy level and currently only written into the generated config (never read back by the job), this would need a way to read the effective value back, or fall back to Xray's documented default of 300s (the panel's own `connIdleDesc` string, `internal/web/translation/en-US.json:1641`). Separately, it may be worth filing this upstream against `github.com/xtls/xray-core` — specifically why `OnlineMap` isn't cleared by the panel's `RemoveUser`/`AddUser` cycle. Example: ```go // internal/web/job/check_client_ip_job.go — partitionLiveIps if observedThisScan[ip] || now-ts < 120 { live = append(live, entry) } ``` `observedThisScan[ip]` alone is sufficient for "live" here — there is no check against that entry's own `LastSeen`/`connIdle` anywhere in this path. Confidence: high for the 3x-ui-side mechanism above (traced end-to-end in the current source, including exact log format and cadence match). Medium for the precise upstream cause of why Xray-core keeps the entry — that lives in `xray-core`, outside this repository, and is inferred from your kernel-level elimination rather than confirmed against its source. @MHSanaei *This reply was generated automatically; 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#4086
No description provided.