[PR #4092] [MERGED] iplimit: dont count idle db-only ips toward the per-client limit (#4091) #5598

Closed
opened 2026-10-31 20:48:05 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/4092
Author: @pwnnex
Created: 4/23/2026
Status: ✅ Merged
Merged: 4/23/2026
Merged by: @pwnnex

Base: main ← Head: fix/iplimit-live-only-slot-count


📝 Commits (1)

  • 5f7c7c5 iplimit: dont count idle db-only ips toward the per-client limit

📊 Changes

3 files changed (+380 additions, -28 deletions)

View changed files

📝 web/job/check_client_ip_job.go (+61 -28)
➕ web/job/check_client_ip_job_integration_test.go (+250 -0)
📝 web/job/check_client_ip_job_test.go (+69 -0)

📄 Description

closes #4091. followup to #4077 / #4083.

what still breaks after #4083

the 30min staleness cutoff wasnt enough. an ip that stopped connecting 5-20 minutes ago still looks fresh to mergeClientIps. the over-limit picker sorts ascending and keeps the oldest, so those quiet-but-still-fresh db entries keep the protected slots. whichever ip is actually connecting right now gets classified as excess and banned every tick. it also never lands in inbound_client_ips.ips, so the panel doesnt show it until you hit the "clear log" button by hand (which is exactly the workaround the reporter found).

fix

only count ips observed in the current access-log scan toward the per-client limit. db-only entries are still persisted so the panel keeps showing them, but they dont participate in the ban decision. the live subset still uses the "protect oldest, ban newcomer" policy.

pulled the split into a small partitionLiveIps helper so the policy is testable without the db.

fail2ban log format is unchanged, so filter.d/3x-ipl.conf keeps matching.

tests

  • 3 unit tests for partitionLiveIps
  • 2 sqlite-backed integration tests for updateInboundClientIps:
    • the pr4091 repro: 3 idle db ips inside the 30min window + 1 live ip with limit=3, expect no ban and the live ip persisted
    • the opposite invariant: 2 live ips with limit=1, newcomer still gets banned

verified the regression test actually catches the bug. stashed the source fix, reran the integration test against pre-fix code: TestUpdateInboundClientIps_LiveIpNotBannedByStillFreshHistoricals failed with shouldCleanLog must be false, nothing should have been banned with 1 live ip under limit 3 (the exact user-reported symptom). popped the stash, all green.

all existing tests still pass.


🔄 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/4092 **Author:** [@pwnnex](https://github.com/pwnnex) **Created:** 4/23/2026 **Status:** ✅ Merged **Merged:** 4/23/2026 **Merged by:** [@pwnnex](https://github.com/pwnnex) **Base:** `main` ← **Head:** `fix/iplimit-live-only-slot-count` --- ### 📝 Commits (1) - [`5f7c7c5`](https://github.com/MHSanaei/3x-ui/commit/5f7c7c5f3d1e470ef07608d382c49ddb1f59767f) iplimit: dont count idle db-only ips toward the per-client limit ### 📊 Changes **3 files changed** (+380 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `web/job/check_client_ip_job.go` (+61 -28) ➕ `web/job/check_client_ip_job_integration_test.go` (+250 -0) 📝 `web/job/check_client_ip_job_test.go` (+69 -0) </details> ### 📄 Description closes #4091. followup to #4077 / #4083. ## what still breaks after #4083 the 30min staleness cutoff wasnt enough. an ip that stopped connecting 5-20 minutes ago still looks fresh to `mergeClientIps`. the over-limit picker sorts ascending and keeps the oldest, so those quiet-but-still-fresh db entries keep the protected slots. whichever ip is actually connecting right now gets classified as excess and banned every tick. it also never lands in `inbound_client_ips.ips`, so the panel doesnt show it until you hit the "clear log" button by hand (which is exactly the workaround the reporter found). ## fix only count ips observed in the current access-log scan toward the per-client limit. db-only entries are still persisted so the panel keeps showing them, but they dont participate in the ban decision. the live subset still uses the "protect oldest, ban newcomer" policy. pulled the split into a small `partitionLiveIps` helper so the policy is testable without the db. fail2ban log format is unchanged, so `filter.d/3x-ipl.conf` keeps matching. ## tests - 3 unit tests for `partitionLiveIps` - 2 sqlite-backed integration tests for `updateInboundClientIps`: - the pr4091 repro: 3 idle db ips inside the 30min window + 1 live ip with limit=3, expect no ban and the live ip persisted - the opposite invariant: 2 live ips with limit=1, newcomer still gets banned verified the regression test actually catches the bug. stashed the source fix, reran the integration test against pre-fix code: `TestUpdateInboundClientIps_LiveIpNotBannedByStillFreshHistoricals` failed with `shouldCleanLog must be false, nothing should have been banned with 1 live ip under limit 3` (the exact user-reported symptom). popped the stash, all green. all existing tests still pass. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-31 20:48:05 +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#5598
No description provided.