[GH-ISSUE #7054] [Performance]: Avoid per-client INFO log storms during Xray config generation #6602

Open
opened 2026-11-07 14:33:26 +07:00 by bsakaguchi · 1 comment
Owner

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():

if enable, exists := enableMap[c.Email]; exists && !enable {
    logger.Infof("Remove Inbound User %s due to expiration or traffic limit", c.Email)
    continue
}

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-ui systemd journal on a PostgreSQL-backed Linux installation with roughly 2,000 disabled/expired client identifiers:

Period (UTC) Observed Remove Inbound User ... due to expiration or traffic limit messages
2026-11-01 to 2026-11-03 02:53 220,351 matching lines involving 1,991 distinct identifiers
2026-11-03 02:31 3,964 messages in one minute for 1,982 distinct identifiers (each appeared twice)
2026-11-02 17:54?17:58 11,796 matching messages across several config / Xray restart sequences

Some 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

  1. Normal INFO logging produces O(number of excluded clients) messages per config generation, potentially thousands at once.
  2. Repeated log writes and formatting add avoidable work and increase journal volume; the precise CPU impact should be benchmarked.
  3. Legitimate restart/hot-apply failures become harder to locate amid thousands of repetitive entries.
  4. The current INFO message includes a per-client identifier even though no lifecycle transition necessarily occurred.

Steps to reproduce

  1. Configure an inbound with a large number of already expired or quota-disabled clients.
  2. Generate/apply the Xray configuration using a supported panel operation.
  3. Inspect journalctl -u x-ui for Remove Inbound User.
  4. Generate the same configuration again without modifying client states.
  5. Observe that each excluded client produces the same INFO message again.

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

  • Preserve the existing exclusion logic and generated Xray configuration exactly.
  • During 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.
  • Move optional per-client details to DEBUG level, preferably with lazy/guarded formatting when DEBUG is disabled; alternatively, emit per-client INFO only on a real state transition, outside the config builder.
  • Add a regression test with thousands of excluded clients confirming:
    • the generated configuration is unchanged;
    • disabled/expired clients remain excluded;
    • INFO log count does not scale with the number of excluded clients;
    • repeated generations do not repeatedly log individual client identifiers.
  • If practical, benchmark config-generation duration and log volume before/after the change.

This should be a logging/observability-only optimization: no modifications to expiry enforcement, user deletion, runtime application, or restart semantics.

  • #4777 ? expired/disabled client behavior and repeated Xray restarts; this report focuses only on INFO log amplification even when a rebuild is legitimate.
  • #5508 ? avoids a forced Xray restart following auto-disable, but does not directly address the GetXrayConfig() per-client INFO log.
  • #7007 / #7014 ? redundant node-sync snapshots, a separate performance path.

This isolates the remaining logging concern so it can be assessed and fixed independently.

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()`](https://github.com/MHSanaei/3x-ui/blob/main/internal/web/service/xray.go): ```go if enable, exists := enableMap[c.Email]; exists && !enable { logger.Infof("Remove Inbound User %s due to expiration or traffic limit", c.Email) continue } ``` 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-ui` systemd journal on a PostgreSQL-backed Linux installation with roughly 2,000 disabled/expired client identifiers: | Period (UTC) | Observed `Remove Inbound User ... due to expiration or traffic limit` messages | | --- | ---: | | 2026-11-01 to 2026-11-03 02:53 | **220,351** matching lines involving **1,991** distinct identifiers | | 2026-11-03 02:31 | **3,964** messages in one minute for **1,982** distinct identifiers (each appeared twice) | | 2026-11-02 17:54?17:58 | **11,796** matching messages across several config / Xray restart sequences | Some 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 1. Normal INFO logging produces O(number of excluded clients) messages per config generation, potentially thousands at once. 2. Repeated log writes and formatting add avoidable work and increase journal volume; the precise CPU impact should be benchmarked. 3. Legitimate restart/hot-apply failures become harder to locate amid thousands of repetitive entries. 4. The current INFO message includes a per-client identifier even though no lifecycle transition necessarily occurred. ## Steps to reproduce 1. Configure an inbound with a large number of already expired or quota-disabled clients. 2. Generate/apply the Xray configuration using a supported panel operation. 3. Inspect `journalctl -u x-ui` for `Remove Inbound User`. 4. Generate the same configuration again without modifying client states. 5. Observe that each excluded client produces the same INFO message again. **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 - Preserve the **existing exclusion logic and generated Xray configuration exactly**. - During `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`. - Move optional per-client details to DEBUG level, preferably with lazy/guarded formatting when DEBUG is disabled; alternatively, emit per-client INFO only on a **real state transition**, outside the config builder. - Add a regression test with thousands of excluded clients confirming: - the generated configuration is unchanged; - disabled/expired clients remain excluded; - INFO log count does not scale with the number of excluded clients; - repeated generations do not repeatedly log individual client identifiers. - If practical, benchmark config-generation duration and log volume before/after the change. This should be a **logging/observability-only optimization**: no modifications to expiry enforcement, user deletion, runtime application, or restart semantics. ## Related work (not duplicates) - #4777 ? expired/disabled client behavior and repeated Xray restarts; this report focuses only on INFO log amplification **even when a rebuild is legitimate**. - #5508 ? avoids a forced Xray restart following auto-disable, but does not directly address the `GetXrayConfig()` per-client INFO log. - #7007 / #7014 ? redundant node-sync snapshots, a separate performance path. This isolates the remaining logging concern so it can be assessed and fixed independently.
Author
Owner

@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 of XrayService.GetXrayConfig():

if enable, exists := enableMap[c.Email]; exists && !enable {
    logger.Infof("Remove Inbound User %s due to expiration or traffic limit", c.Email)
    continue
}

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() at internal/web/service/xray.go:1504 builds the config before comparing it with the running one (configUnchanged := process.GetConfig().Equals(xrayConfig)). A no-op reconcile still logs the whole list. RestartXray is called by:
    • the 30 s needs-restart cron (cadenceXrayRestart = "@every 30s", internal/web/web.go:304);
    • the auto-disable path (internal/web/job/xray_traffic_job.go:96);
    • node traffic sync (internal/web/job/node_traffic_sync_job.go:145);
    • the crash watchdog (internal/web/job/check_xray_running_job.go:33);
    • every panel-triggered restart.
  • GetConfigJson() at internal/web/service/server.go:1620, used when you view the generated config.
  • The Xray update pre-check at internal/web/service/server.go:1209.

There are two side effects worth knowing about:

  • logger.Infof also appends every line to the in-memory buffer behind the panel's log viewer (internal/logger/logger.go:163). That buffer keeps at most maxLogBufferSize = 10240 entries (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.
  • On your proposal for lazy DEBUG formatting: logger.Debugf alone would not save the formatting cost here. It always runs addToBuffer("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 since 85e2ded0.
Same class: None found. This is the only per-client log line in the filter (searched internal/ for Remove Inbound User and due 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 the configUnchanged check); internal/web/web.go:304; internal/logger/logger.go:151,163,21
Not determined: How much CPU the log writes cost on the reporter's host. A before/after profile of GetXrayConfig with about 2,000 excluded clients would settle it.

Suggested fix: In GetXrayConfig(), count the clients excluded by the enableMap check and emit at most one summary line per build, or none when the count hasn't changed since the last build. Remove the per-client Infof. 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.

<!-- gh-comment-id:6594748371 --> @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 of `XrayService.GetXrayConfig()`: ```go if enable, exists := enableMap[c.Email]; exists && !enable { logger.Infof("Remove Inbound User %s due to expiration or traffic limit", c.Email) continue } ``` 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()` at `internal/web/service/xray.go:1504` builds the config *before* comparing it with the running one (`configUnchanged := process.GetConfig().Equals(xrayConfig)`). A no-op reconcile still logs the whole list. `RestartXray` is called by: - the 30 s needs-restart cron (`cadenceXrayRestart = "@every 30s"`, `internal/web/web.go:304`); - the auto-disable path (`internal/web/job/xray_traffic_job.go:96`); - node traffic sync (`internal/web/job/node_traffic_sync_job.go:145`); - the crash watchdog (`internal/web/job/check_xray_running_job.go:33`); - every panel-triggered restart. - `GetConfigJson()` at `internal/web/service/server.go:1620`, used when you view the generated config. - The Xray update pre-check at `internal/web/service/server.go:1209`. There are two side effects worth knowing about: - `logger.Infof` also appends every line to the in-memory buffer behind the panel's log viewer (`internal/logger/logger.go:163`). That buffer keeps at most `maxLogBufferSize = 10240` entries (`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. - On your proposal for lazy DEBUG formatting: `logger.Debugf` alone would not save the formatting cost here. It always runs `addToBuffer("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 since `85e2ded0`. Same class: None found. This is the only per-client log line in the filter (searched `internal/` for `Remove Inbound User` and `due 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 the `configUnchanged` check); `internal/web/web.go:304`; `internal/logger/logger.go:151,163,21` Not determined: How much CPU the log writes cost on the reporter's host. A before/after profile of `GetXrayConfig` with about 2,000 excluded clients would settle it. Suggested fix: In `GetXrayConfig()`, count the clients excluded by the `enableMap` check and emit at most one summary line per build, or none when the count hasn't changed since the last build. Remove the per-client `Infof`. 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.* <!-- claude-issue:analyst -->
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#6602
No description provided.