mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5893] [Bug]: [LIMIT_IP] Stale IP stays "online" and re-triggers ban for minutes after real TCP connection is already closed #4086
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4086
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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:
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
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 itExpected 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
@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.GetUsersStatsRPC (internal/xray/api.go:711-742, viaXrayService.GetOnlineUsers,internal/web/service/xray.go:833-861), backed by thestatsUserOnlinepolicy the panel force-enables on every policy level (ensureStatsPolicy,internal/web/service/xray.go:667-710— note this function never touchesconnIdleitself). That RPC does return aLastSeenunix timestamp per IP (internal/xray/api.go:694-699: "the unix time (seconds) the core last dispatched a link from it"), but nothing incheck_client_ip_job.goever compares it againstconnIdleor against "now" to decide liveness:Run()callsprocessObserved(observed, enforce, true)(line 68) — the trailingtrueisobservedAreLive, hardcoded for every API-sourced observation.mergeClientIps(lines 391-408),newAlwaysLiveskips the job's only staleness cutoff (ipStaleAfterSeconds, 30 minutes, line 42) for these entries entirely.partitionLiveIps(lines 420-438), an IP counts as "live" onceobservedThisScan[ip]is true (line 429) — i.e. "Xray listed it this scan" — regardless of how old that same entry'sLastSeenis.So the job's liveness signal reduces to "did
GetUsersStatsstill 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 IPline (line 530).One more relevant data point: every one of those hits also runs
RemoveUserthenAddUserfor 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 (emptyss -tnp, no effect fromtcp_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 thegithub.com/xtls/xray-coredependency (pinned ingo.modatv1.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
maxretryto absurd values to avoid banning legitimate customers, which defeats the feature's actual purpose (detecting concurrent/shared-credential usage). It also causes needlessRemoveUser/AddUserchurn 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) againstnow, and stop treating an IP as live once that gap exceedsconnIdleplus a small buffer (e.g. one scan interval). That caps the worst case at roughlyconnIdle+ 10s regardless of how long Xray's own bookkeeping lags, matching the "~70-80s" you expected. SinceconnIdleis 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 ownconnIdleDescstring,internal/web/translation/en-US.json:1641). Separately, it may be worth filing this upstream againstgithub.com/xtls/xray-core— specifically whyOnlineMapisn't cleared by the panel'sRemoveUser/AddUsercycle.Example:
observedThisScan[ip]alone is sufficient for "live" here — there is no check against that entry's ownLastSeen/connIdleanywhere 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.