[PR #4581] [MERGED] Prevent executing fail2ban if it is disabled by env to prevent small CPU spikes every 10s, because python in fail2ban is slow #5720

Closed
opened 2026-11-02 04:03:35 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/4581
Author: @Mayurifag
Created: 5/26/2026
Status: ✅ Merged
Merged: 6/1/2026
Merged by: @MHSanaei

Base: main ← Head: fix/fail2ban-disabled-ip-limit


📝 Commits (3)

  • cb2d7db fix(job): skip fail2ban IP limit when disabled
  • 0b39087 Merge branch 'main' into fix/fail2ban-disabled-ip-limit
  • 54d444d Merge branch 'main' into fix/fail2ban-disabled-ip-limit

📊 Changes

3 files changed (+134 additions, -5 deletions)

View changed files

📝 web/job/check_client_ip_job.go (+16 -5)
📝 web/job/check_client_ip_job_integration_test.go (+43 -0)
📝 web/job/check_client_ip_job_test.go (+75 -0)

📄 Description

Summary

Fix CheckClientIpJob so XUI_ENABLE_FAIL2BAN=false disables fail2ban-dependent IP-limit work inside the Go app, not only in DockerEntrypoint.sh.

Why

Observed on ghcr.io/mhsanaei/3x-ui:v3.1.0: the Docker image always installs fail2ban, so /usr/bin/fail2ban-client exists even when fail2ban is intentionally disabled with XUI_ENABLE_FAIL2BAN=false.

DockerEntrypoint.sh only starts/configures fail2ban when XUI_ENABLE_FAIL2BAN=true, but the Go app still scheduled CheckClientIpJob every 10 seconds. When IP-limit logic was active, that job called fail2ban-client -h every run to check whether fail2ban was installed. Because fail2ban-client is Python, live sampling caught short-lived /usr/bin/python3 /usr/bin/fail2ban-client -h processes during small idle CPU spikes.

When fail2ban is disabled by env, the app should also skip fail2ban-dependent IP-limit behavior and avoid writing ban entries that no fail2ban daemon will consume.

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

  • go test ./web/job
  • go test ./... with local web/dist/.gitkeep stub matching the CI workflow
  • go build ./... with local web/dist/.gitkeep stub matching the CI workflow
  • git diff --check

Screenshots / recordings

N/A

Breaking changes

None. XUI_ENABLE_FAIL2BAN=true keeps the existing behavior, and an unset env var still defaults to enabled for non-Docker/manual installs. The Dockerfile already defaults XUI_ENABLE_FAIL2BAN=true.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: N/A, no frontend changes.
  • I updated the Wiki / README / API docs if user-facing behavior changed: N/A, no docs needed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/4581 **Author:** [@Mayurifag](https://github.com/Mayurifag) **Created:** 5/26/2026 **Status:** ✅ Merged **Merged:** 6/1/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/fail2ban-disabled-ip-limit` --- ### 📝 Commits (3) - [`cb2d7db`](https://github.com/MHSanaei/3x-ui/commit/cb2d7db665942d30ba3dacbac42048ec04af1501) fix(job): skip fail2ban IP limit when disabled - [`0b39087`](https://github.com/MHSanaei/3x-ui/commit/0b3908749b6c9ba79d92d0e6aaa27832917dfd07) Merge branch 'main' into fix/fail2ban-disabled-ip-limit - [`54d444d`](https://github.com/MHSanaei/3x-ui/commit/54d444dc7f18e32f30245e963e1e5f58b2e2bae2) Merge branch 'main' into fix/fail2ban-disabled-ip-limit ### 📊 Changes **3 files changed** (+134 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `web/job/check_client_ip_job.go` (+16 -5) 📝 `web/job/check_client_ip_job_integration_test.go` (+43 -0) 📝 `web/job/check_client_ip_job_test.go` (+75 -0) </details> ### 📄 Description ## Summary Fix `CheckClientIpJob` so `XUI_ENABLE_FAIL2BAN=false` disables fail2ban-dependent IP-limit work inside the Go app, not only in `DockerEntrypoint.sh`. ## Why Observed on `ghcr.io/mhsanaei/3x-ui:v3.1.0`: the Docker image always installs fail2ban, so `/usr/bin/fail2ban-client` exists even when fail2ban is intentionally disabled with `XUI_ENABLE_FAIL2BAN=false`. `DockerEntrypoint.sh` only starts/configures fail2ban when `XUI_ENABLE_FAIL2BAN=true`, but the Go app still scheduled `CheckClientIpJob` every 10 seconds. When IP-limit logic was active, that job called `fail2ban-client -h` every run to check whether fail2ban was installed. Because `fail2ban-client` is Python, live sampling caught short-lived `/usr/bin/python3 /usr/bin/fail2ban-client -h` processes during small idle CPU spikes. When fail2ban is disabled by env, the app should also skip fail2ban-dependent IP-limit behavior and avoid writing ban entries that no fail2ban daemon will consume. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [ ] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [ ] Xray config generation - [ ] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [ ] Database / migrations - [ ] Install / upgrade script - [x] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? - `go test ./web/job` - `go test ./...` with local `web/dist/.gitkeep` stub matching the CI workflow - `go build ./...` with local `web/dist/.gitkeep` stub matching the CI workflow - `git diff --check` ## Screenshots / recordings N/A ## Breaking changes None. `XUI_ENABLE_FAIL2BAN=true` keeps the existing behavior, and an unset env var still defaults to enabled for non-Docker/manual installs. The Dockerfile already defaults `XUI_ENABLE_FAIL2BAN=true`. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: N/A, no frontend changes. - [x] I updated the Wiki / README / API docs if user-facing behavior changed: N/A, no docs needed. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:03:35 +07:00
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#5720
No description provided.