mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #6590] [MERGED] fix(ip-limit): append fail2ban lines only after the scan commits #6364
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#6364
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?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6590
Author: @n0ctal
Created: 9/17/2026
Status: ✅ Merged
Merged: 9/26/2026
Merged by: @MHSanaei
Base:
main← Head:upstream-ban-publish-after-commit📝 Commits (1)
ccaccddfix(ip-limit): append fail2ban lines only after the scan commits📊 Changes
4 files changed (+339 additions, -88 deletions)
View changed files
➕
internal/web/job/check_client_ip_ban_commit_test.go(+212 -0)📝
internal/web/job/check_client_ip_frozen_ban_test.go(+3 -5)📝
internal/web/job/check_client_ip_job.go(+101 -68)📝
internal/web/job/check_client_ip_job_integration_test.go(+23 -15)📄 Description
Summary
The IP-limit scan wrote its fail2ban lines from inside the database
transaction, so a scan that later failed to commit still banned the addresses
it had decided on.
Why
updateInboundClientIpsopenedGetIPLimitLogPath()and wrote the[LIMIT_IP] …lines while the caller's transaction was still open. Iftx.Commit()then returned an error, the IP-tracking rows rolled back but thefail2ban trigger file had already been appended to, and fail2ban acts on the
file, not on the database. The ban is not reversible from the panel.
The same path advanced
bannedSeenbefore the commit. On the next scan theaddresses looked "already banned", so the retry that should have followed the
rollback was suppressed: the client was banned on state that never existed,
and the panel had no record of it.
Scope
updateInboundClientIpsreturns ban candidates instead of publishing them;it no longer opens the log file or touches
bannedSeen.publishBansruns aftertx.Commit()succeeds, opens the log once forthe whole batch, and records
bannedSeenonly after a line is written.writeBanLinestakes anio.Writerand checks thefmt.Fprintferror, so ashort write leaves the ban retryable instead of silently marking it done.
selectAdvancedSinceLastBanis now a pure filter; the prune of stalebannedSeenentries runs for every enforced client, so a client that dropsback under its limit is forgotten and can be banned again if it returns.
The log wording is unchanged, byte for byte, including the
2006/01/02 15:04:05prefix thatlog.LstdFlagsproduced:x-ui.shcreate_iplimit_jailsbuildsfilter.d/3x-ipl.conffailregexfrom it.Validation
go test ./internal/web/job/passes on this branch, rebased onto1c0ce80e.TestProcessObserved_CommitFailureDoesNotPublishBanis the guard. MovingpublishBansback abovetx.Commit()— the behaviour before this change —fails it on both assertions:
Four further tests cover the publish-failure retry, the
bannedSeenprunewhen a client returns under its limit, the
writeBanLineswrite error, andthe committed happy path.
go build ./...andgo vet ./internal/web/job/are clean.Risk
Low. The change is confined to when the lines are written, not what they say;
a failed publish now defers the ban to the next scan rather than losing it.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.