mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[GH-ISSUE #6286] [Bug]: client IP entries never expire once a client stops connecting #4269
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#4269
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 @rokokol on GitHub (Aug 22, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6286
Describe the bug
The 30-minute eviction of stored client IPs is intentional: PR #4321 proposed keeping the history and was closed with "the 30-minute eviction is intentional; without it the per-client IP blob grows unbounded". That invariant does not hold in practice, because the eviction is a filter applied while a row is being rewritten, and a row is only rewritten when its client shows up in the current online-stats scan.
CheckClientIpJob.processObservedloads rows withwhere client_email IN (observed emails), and nothing ever visits the rest of the table. So the moment a client stops connecting, its last blob freezes with the addresses and timestamps it had at that point, and it is kept indefinitely —mergeClientIpsnever runs for that row again, soipStaleAfterSecondsstops being an upper bound on retention.The same applies to
node_client_ips, written byrecordLocalAttribution. On top of that,Runreturns early when fail2ban is not enabled, so on those panels nothing is pruned at all while previously written rows stay where they are.How to reproduce the problem
inbound_client_ipsrow fills with (ip, timestamp) entriesselect client_email, ips from inbound_client_ips;— the row still carries the same addresses with their original timestamps, and it will keep them indefinitelyExpected behavior
No stored address outlives
ipStaleAfterSeconds, whether or not its client is currently online. The retention rule stated in #4321 should hold for every row, not only for the rows that happen to be rewritten.Actual behavior
Rows belonging to inactive clients retain their addresses forever. On one of our nodes the stored entries were between 32 and 38 hours old at the time of the query, all of them for clients that were simply offline. In a related case (#6285) rows survived eight days after the node they belonged to changed its
panelGuid.The practical effect is that a panel accumulates client IP addresses far beyond the retention the code intends, and there is no supported way to inspect how much is kept or to clear it.
A possible fix would be to apply the same cutoff in a periodic sweep: every few minutes, prune every row regardless of observation, dropping entries older than the cutoff and deleting rows that end up empty. Both tables hold one row per client per guid, so a full pass is cheap next to the job's own 10-second cadence.
Relevant logs
Emails are replaced with placeholders and addresses are removed; only the timestamps matter here.
All three clients were offline for that whole period, so their rows were never revisited and the 30-minute cutoff was never applied to them.
3x-ui version
3.6.0
Xray-core version
26.7.28
How did you install 3x-ui?
install.sh script
Operating system
Ubuntu 24.04.4 LTS
Which parts of the panel are affected?
Database / migrations, Multi-node (sub-nodes)
Before submitting
@github-actions[bot] commented on GitHub (Aug 22, 2026):
Confirmed — this is a real bug and it is still present on the default branch (
1250fbb7). Your reading of the mechanism is correct:ipStaleAfterSecondsis only ever applied while a row is being rewritten, and only rows whose email appears in the current online-stats scan are ever rewritten.Root cause
CheckClientIpJob.processObservedderives its entire work list from the scan:loadClientIpRowsthen narrows the table to exactly those emails —db.Where("client_email IN ?", batch).Find(&rows)(check_client_ip_job.go:251) — and the loop at:307iteratesemailsonly. The cutoff itself lives one layer further in, inside the rewrite:So a row whose client stops connecting is never selected, never merged, and never pruned.
ipStaleAfterSeconds(check_client_ip_job.go:45,int64(30 * 60)) is a cutoff applied on write, not a retention bound.node_client_ipshas the same shape, andupsertNodeClientIpsmakes it especially visible: it already loads every row for the guid atinternal/web/service/inbound_node_ips.go:58-61, then throws that away and iterates only the incoming emails —— so the
len(merged) == 0delete at:90-101can only ever fire for a client that is still being observed.This is not a regression. The cutoff has been applied inside the merge since
eef2d311("Fix IP Limit continuous ban loop from stale DB entries (#4077)"), andnode_client_ipsinherited that shape when it was added in9385b6c6.Two things your report did not have
1. The flat table is partly swept on a master/node pair;
node_client_ipsis not.node_traffic_sync_job.go:436-454ships the wholeinbound_client_ipstable in both directions (FetchAllClientIps→MergeInboundClientIps, thenPushAllClientIpsback), andMergeInboundClientIpsapplies the cutoff to every incoming row (inbound_client_ips.go:80,137). That givesinbound_client_ipsan indirect full-table pass whenever IP sync runs.node_client_ipsgets no equivalent, becauseGetClientIpsByGuidalready drops stale entries and skips empty rows before they leave the node (inbound_node_ips.go:161-174) — the master therefore never sees a stale attribution row to prune. That is almost certainly why your evidence came out ofnode_client_ipsrather thaninbound_client_ips. On a standalone panel with no nodes, neither table is swept at all.2. Deleted and renamed clients leave
node_client_ipsrows behind permanently. Client deletion removes the flat row and the node traffic row but not the attribution row:There is no
model.NodeClientIpdelete on that path, andUpdateClientIPs(inbound_client_ips.go:154-163) re-keys only the flat table on rename. Since nothing ever revisits an unobserved row, those become permanent orphans — that is row-count growth, not just frozen timestamps, and it strengthens the case beyond the retention argument.On your other points
Runearly return is real.check_client_ip_job.go:62-64returns beforeprocessObservedwhenXUI_ENABLE_FAIL2BANis set to anything other thantrue(isFail2BanEnabled,:472-475; default is enabled,.env.example:69). Worth noting that on those panels nothing is collected either, so the IP Log freezes at its last value rather than merely going unpruned.TestUpsertNodeClientIps_EmptyMergeDeletesRow(internal/web/service/inbound_node_ips_test.go:69-93) exists specifically so that "the merge yields nothing fresh, so the row must be removed (not left lingering)". Nothing in the tree pins the opposite behaviour, and the maintainer's comment you quoted from #4321 is accurate as quoted.1787393116: 135281 s (37.6 h), 117261 s (32.6 h) and 132171 s (36.7 h), and the UTC conversions match.node_client_ips, not for the flat table. There is a per-client clear —POST /panel/api/clients/clearIps/:email(internal/web/controller/client.go:78), the same action the IP Log's clear button uses — butClearClientIpsonly blanksinbound_client_ips.ips(inbound_client_ips.go:227-238) and leaves the attribution rows untouched. So it is a partial workaround for the display set only.Verdict: Confirmed bug
Severity: Medium
Confidence: High
Root cause:
CheckClientIpJob.processObserved(internal/web/job/check_client_ip_job.go:274-278,:307) only visits emails present in the current online-stats scan, andloadClientIpRows(:251) restricts the query to those emails, so theipStaleAfterSecondscutoff applied insidemergeClientIps(:519) is unreachable for any row whose client is offline.upsertNodeClientIps(internal/web/service/inbound_node_ips.go:69-84) has the same defect fornode_client_ipsdespite already holding every row for the guid at:58-61. Triggered by any client that stops connecting; not a regression — the cutoff has been rewrite-scoped sinceeef2d311, andnode_client_ipsinherited the shape in9385b6c6.Already fixed: Still present on the default branch (
1250fbb7); no change to these files sincev3.6.0other thand6472740and2a8c3bc0, neither of which touches the selection path.Duplicate of: Related: #6285 — same "an unobserved row is never revisited" property, but a different root cause there (
UpdateHeartbeatnot re-keying or purging the previous guid). Related: #5423 raised the retention question as a feature request.Evidence:
check_client_ip_job.go:45const ipStaleAfterSeconds = int64(30 * 60);:251db.Where("client_email IN ?", batch).Find(&rows);:274-278,:307,:519;:62-64fail2ban early return;inbound_node_ips.go:58-61(all rows loaded) vs:69-84(only incoming emails iterated) and:90-101(delete unreachable for unobserved emails);:161-174GetClientIpsByGuidfilters before the wire, which is why the master's merge never prunes;inbound_client_ips.go:80,137(cutoff applied per incoming row) withnode_traffic_sync_job.go:436-454(whole table shipped both ways);client_crud.go:844-849deletesInboundClientIpsandNodeClientTrafficbut notNodeClientIp;inbound_node_ips_test.go:69-93states the "not left lingering" intent.Not determined: Whether the panel you queried is a master or a sub-node, and whether node IP sync was running on it. It changes only how much of
inbound_client_ipswas being swept indirectly; it does not affect thenode_client_ipsfinding, which your log block is what actually demonstrates.select count(*) from nodes where enable = 1 and status = 'online';on that box would settle it.Suggested fix: A periodic full-table pass over
inbound_client_ipsandnode_client_ipsthat applies the same cutoff regardless of observation and deletes rows that end up empty, as you proposed — both tables are one row per client per guid, so it is cheap next to the job's 10s cadence. It would need to run independently of theisFail2BanEnabledgate atcheck_client_ip_job.go:62-64, or panels with fail2ban disabled keep their frozen rows.This reply was generated automatically; a maintainer may follow up.
@rokokol commented on GitHub (Aug 22, 2026):
The log block came from a sub-node, not from the master, and node IP sync was running:
select count(*) from nodes where enable = 1 and status = 'online';returns 2 on the master. So thenode_client_ipsevidence falls exactly under the case described above — the node prunes before the wire, the master never sees a stale attribution row, and nothing sweeps the node's own copy.The second finding reproduces here as well. On our master, 15 rows in
node_client_ipsbelong to clients that no longer exist inclients, spread across all three live guids — so this is row-count growth in a live deployment, not just a theoretical path.