mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[GH-ISSUE #7054] [Performance]: Avoid per-client INFO log storms during Xray config generation #6602
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#6602
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 @HamedSanaei on GitHub (Nov 3, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/7054
Summary
XrayService.GetXrayConfig()emits an INFO log entry for every expired/traffic-disabled client while building the Xray configuration. The same client is logged again on later configuration generations, even if its state has not changed.The log message is misleading in this context: "Remove Inbound User" describes excluding a client from the generated config, not necessarily performing a new deletion or a new lifecycle transition.
Source
internal/web/service/xray.go?GetXrayConfig():Because the statement is inside the client loop, the number of INFO messages grows with the number of excluded clients for each configuration generation, independently of whether any client actually changed state.
Production evidence (sanitized)
Read-only analysis of the
x-uisystemd journal on a PostgreSQL-backed Linux installation with roughly 2,000 disabled/expired client identifiers:Remove Inbound User ... due to expiration or traffic limitmessagesSome unchanged identifiers appeared 113 times in the analyzed interval. This is repetitive configuration-generation logging rather than evidence of 113 actual removals.
The host has 2 vCPUs and has experienced high CPU utilization, but the fraction attributable to logging has not been measured. This report does not claim the logging caused the CPU spikes, caused Xray restarts, or incorrectly disabled clients.
No client IDs, email addresses, domains, IP addresses, credentials, or raw customer logs are included.
Why this matters
Steps to reproduce
journalctl -u x-uiforRemove Inbound User.Actual: Thousands of per-client INFO entries are produced on each config generation.
Expected: Normal INFO logging summarizes exclusion counts without emitting repeated per-client messages when no client state has changed.
Proposed change
GetXrayConfig(), count filtered clients and issue one aggregated INFO message per generation, for example:Xray config generated: excluded 1,982 disabled/expired clients across N inbounds.This should be a logging/observability-only optimization: no modifications to expiry enforcement, user deletion, runtime application, or restart semantics.
Related work (not duplicates)
GetXrayConfig()per-client INFO log.This isolates the remaining logging concern so it can be assessed and fixed independently.
@github-actions[bot] commented on GitHub (Nov 3, 2026):
Confirmed. On the current default branch, every Xray config build writes one INFO line for each client whose traffic row is disabled. It does this whether or not the client's state changed since the last build. The config that gets built is correct; the problem is only the log volume and the misleading wording.
What the code does
internal/web/service/xray.go:247-250, inside the per-client loop ofXrayService.GetXrayConfig():This only leaves the client out of the config being built. It doesn't remove anyone. The actual disable happens earlier, in the traffic job. So each rebuild repeats one line for every already-disabled client, which matches your numbers: about 1,982 lines per build, and twice per minute when two builds land close together.
GetXrayConfig()runs on every rebuild, including rebuilds where nothing ends up changing:RestartXray()atinternal/web/service/xray.go:1504builds the config before comparing it with the running one (configUnchanged := process.GetConfig().Equals(xrayConfig)). A no-op reconcile still logs the whole list.RestartXrayis called by:cadenceXrayRestart = "@every 30s",internal/web/web.go:304);internal/web/job/xray_traffic_job.go:96);internal/web/job/node_traffic_sync_job.go:145);internal/web/job/check_xray_running_job.go:33);GetConfigJson()atinternal/web/service/server.go:1620, used when you view the generated config.internal/web/service/server.go:1209.There are two side effects worth knowing about:
logger.Infofalso appends every line to the in-memory buffer behind the panel's log viewer (internal/logger/logger.go:163). That buffer keeps at mostmaxLogBufferSize = 10240entries (logger.go:21). With about 2,000 excluded clients, five rebuilds are enough to push every other entry out of the panel's log view.logger.Debugfalone would not save the formatting cost here. It always runsaddToBuffer("DEBUG", fmt.Sprintf(format, args...))(internal/logger/logger.go:151), whatever the configured level. Debug-level logging would need its own guard, or the per-client line should be dropped and replaced by a single summary count.I can't measure how much CPU this costs on your host. I agree with your report that it hasn't been measured.
Verdict: Confirmed bug
Severity: Low
Confidence: High
Root cause:
internal/web/service/xray.go:248,GetXrayConfig(): an INFO line is emitted inside the per-client filter that runs on every config build, so it repeats for unchanged disabled clients. Present since85e2ded0.Same class: None found. This is the only per-client log line in the filter (searched
internal/forRemove Inbound Useranddue to expiration). All rebuild paths reach this one function, as listed above.Already fixed: Still present on the default branch (
eae4725d); not changed in v3.11.0.Duplicate of: Related: #4777 (restarts triggered by disabled clients; a different root cause)
Evidence:
internal/web/service/xray.go:247-250(quoted above);xray.go:1504(build before theconfigUnchangedcheck);internal/web/web.go:304;internal/logger/logger.go:151,163,21Not determined: How much CPU the log writes cost on the reporter's host. A before/after profile of
GetXrayConfigwith about 2,000 excluded clients would settle it.Suggested fix: In
GetXrayConfig(), count the clients excluded by theenableMapcheck and emit at most one summary line per build, or none when the count hasn't changed since the last build. Remove the per-clientInfof. The per-client transition is already a real event in the traffic job's auto-disable path, so that is where a per-client log belongs. The exclusion logic and the generated config should stay exactly as they are.This reply was generated automatically; a maintainer may follow up.