[PR #6830] [MERGED] fix(iplimit): keep recording client IPs with fail2ban disabled #6470

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6830
Author: @yudongyouqing
Created: 10/15/2026
Status: ✅ Merged
Merged: 10/24/2026
Merged by: @MHSanaei

Base: main ← Head: fix/ip-tracking-decouple-fail2ban


📝 Commits (6)

  • 388d20a fix(iplimit): keep recording client IPs with fail2ban disabled (#6722)
  • a3bf389 fix(iplimit): address review findings on the #6722 test and comments
  • bbcb46e fix(iplimit): stable tied-timestamp blobs and a zero-value-safe scan
  • be8d955 refactor(iplimit): platform-pure resolveEnforce and review cleanups
  • 8f68fdd Merge remote-tracking branch 'origin/main' into pr/6830
  • b53caf2 refactor(iplimit): drop the nil-source guard and keep Run's comments by their code

📊 Changes

4 files changed (+192 additions, -48 deletions)

View changed files

📝 docs/architecture.md (+1 -1)
📝 internal/web/job/check_client_ip_job.go (+77 -47)
📝 internal/web/job/check_client_ip_job_integration_test.go (+62 -0)
📝 internal/web/job/check_client_ip_job_test.go (+52 -0)

📄 Description

Fixes #6722

What

XUI_ENABLE_FAIL2BAN=false made check_client_ip_job.Run() return before any IP was persisted, so the panel's client-IP list went empty on fail2ban-disabled installs even though the online-stats collection had already run that tick. Enforcement is now the only thing the env var gates: the scan always records, and resolveEnforce folds the flag in so Windows (where the disconnect path needs no fail2ban binary) stops enforcing too when it is disabled.

Collection-only runs (no limit on the client, inbound disabled, or fail2ban off) now share the enforcing run's merge + 30-minute window + CAS write instead of overwriting the blob with the current scan: the panel keeps showing recently connected IPs (what #6722 asks for), concurrent node-sync writes into the same blob are no longer lost (#6587), and unchanged scans skip the DB write entirely.

A narrow onlineUsersSource interface replaces the concrete XrayService field so Run() can be driven end to end in tests without a live core.

Tests (each written red first)

  • TestRun_RecordsIpsWhenFail2banDisabled — reproduced the reported bug (no inbound_client_ips row created with fail2ban disabled); now asserts the observed IP is recorded and no ban lines are written.
  • TestProcessObserved_CollectionOnlyKeepsRecentWindow — pins the 30-minute window for collection-only runs; the old branch dropped an IP seen five minutes earlier.
  • TestResolveEnforce — table test including the Windows-shaped row (disabled env + fail2ban installed → no enforcement), the only row distinguishing the new guard on Linux.

internal/web/job and internal/web/service pass with -race -shuffle=on; whole-repo golangci-lint clean. make verify is green here except msw-worker-check, which fails on current main as well and is fixed by #6829 (merge that first).

Docs: the docs/architecture.md cron-table row for this job now states both duties.


🔄 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/6830 **Author:** [@yudongyouqing](https://github.com/yudongyouqing) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/24/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/ip-tracking-decouple-fail2ban` --- ### 📝 Commits (6) - [`388d20a`](https://github.com/MHSanaei/3x-ui/commit/388d20adaba5b9658d54cf6c41e6371e59301ce7) fix(iplimit): keep recording client IPs with fail2ban disabled (#6722) - [`a3bf389`](https://github.com/MHSanaei/3x-ui/commit/a3bf389f26f8d6b37f68dccda9917b4a88390260) fix(iplimit): address review findings on the #6722 test and comments - [`bbcb46e`](https://github.com/MHSanaei/3x-ui/commit/bbcb46e30fab71acc0bd9b026a9e364889f5380f) fix(iplimit): stable tied-timestamp blobs and a zero-value-safe scan - [`be8d955`](https://github.com/MHSanaei/3x-ui/commit/be8d955bef5c5e527af9a0b4101eeb2ab98e1326) refactor(iplimit): platform-pure resolveEnforce and review cleanups - [`8f68fdd`](https://github.com/MHSanaei/3x-ui/commit/8f68fdddaa776858c2a2052ae562da005117ab7d) Merge remote-tracking branch 'origin/main' into pr/6830 - [`b53caf2`](https://github.com/MHSanaei/3x-ui/commit/b53caf2e02a0ef7131c1172aa62d0adf89ce9d6e) refactor(iplimit): drop the nil-source guard and keep Run's comments by their code ### 📊 Changes **4 files changed** (+192 additions, -48 deletions) <details> <summary>View changed files</summary> 📝 `docs/architecture.md` (+1 -1) 📝 `internal/web/job/check_client_ip_job.go` (+77 -47) 📝 `internal/web/job/check_client_ip_job_integration_test.go` (+62 -0) 📝 `internal/web/job/check_client_ip_job_test.go` (+52 -0) </details> ### 📄 Description Fixes #6722 ## What `XUI_ENABLE_FAIL2BAN=false` made `check_client_ip_job.Run()` return before any IP was persisted, so the panel's client-IP list went empty on fail2ban-disabled installs even though the online-stats collection had already run that tick. Enforcement is now the only thing the env var gates: the scan always records, and `resolveEnforce` folds the flag in so Windows (where the disconnect path needs no fail2ban binary) stops enforcing too when it is disabled. Collection-only runs (no limit on the client, inbound disabled, or fail2ban off) now share the enforcing run's merge + 30-minute window + CAS write instead of overwriting the blob with the current scan: the panel keeps showing recently connected IPs (what #6722 asks for), concurrent node-sync writes into the same blob are no longer lost (#6587), and unchanged scans skip the DB write entirely. A narrow `onlineUsersSource` interface replaces the concrete `XrayService` field so `Run()` can be driven end to end in tests without a live core. ## Tests (each written red first) - `TestRun_RecordsIpsWhenFail2banDisabled` — reproduced the reported bug (no `inbound_client_ips` row created with fail2ban disabled); now asserts the observed IP is recorded and no ban lines are written. - `TestProcessObserved_CollectionOnlyKeepsRecentWindow` — pins the 30-minute window for collection-only runs; the old branch dropped an IP seen five minutes earlier. - `TestResolveEnforce` — table test including the Windows-shaped row (disabled env + fail2ban installed → no enforcement), the only row distinguishing the new guard on Linux. `internal/web/job` and `internal/web/service` pass with `-race -shuffle=on`; whole-repo `golangci-lint` clean. `make verify` is green here except `msw-worker-check`, which fails on current `main` as well and is fixed by #6829 (merge that first). Docs: the `docs/architecture.md` cron-table row for this job now states both duties. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:09:00 +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#6470
No description provided.