mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6176] [MERGED] fix(database): keep IP limits when the fail2ban probe is inconclusive #6138
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#6138
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/6176
Author: @n0ctal
Created: 8/5/2026
Status: ✅ Merged
Merged: 8/14/2026
Merged by: @MHSanaei
Base:
main← Head:upstream-preserve-configured-iplimit📝 Commits (3)
dfd4ed3fix(database): keep IP limits when the fail2ban probe is inconclusive1a3130ctest(database): cover fail2ban reset safeguards2e8d65fMerge branch 'main' into upstream-preserve-configured-iplimit📊 Changes
2 files changed (+135 additions, -5 deletions)
View changed files
📝
internal/database/db.go(+26 -5)➕
internal/database/fail2ban_state_test.go(+109 -0)📄 Description
Summary
ResetIpLimitNoFail2banwiped every configuredlimitIpwheneverfail2ban-client -hfailed for any reason, including a transient one, and then recorded itself so the decision was never revisited. Distinguish "fail2ban is absent" from "the probe failed".Why
The seeder's intent is sound: with no fail2ban there is nothing to enforce
limitIp, so clearing it avoids a setting that silently does nothing.The problem is the evidence it acts on.
exec.Command("fail2ban-client", "-h").Run() == nilis false both when the binary does not exist and when it exists but that one run failed — a panel started before fail2ban is up, an image where fail2ban is installed a moment later, a momentarily unavailable exec.The consequence is not proportional to the uncertainty: it rewrites every inbound's settings JSON and every
clients.limit_ipto 0, recordsResetIpLimitNoFail2banin the seeder history, and returns. There is no log line on the destructive path, and because the history row exists the seeder never looks again. Operator configuration is gone with nothing to restore it from.Scope
internal/database/db.go—fail2banEnforcementState()returnsfail2banEnforcing/fail2banAbsent/fail2banUnknown; a missing binary (exec.LookPath) is still absent, a present-but-unrunnable one is unknown.fail2banCanEnforce()keeps its signature for existing callers.fail2banUnknown, logs the probe error, and does not record itself, so the next start re-evaluates. Behaviour on absent and on enforcing is unchanged.internal/database/fail2ban_state_test.go— covers all three states with a stubfail2ban-clientonPATH.Validation
go test ./internal/database/ -count=1green;go build ./...andgo vetclean.Risk
Low, and strictly less destructive than before. A host that genuinely lacks fail2ban still gets the cleanup on the same schedule. The only new outcome is that an inconclusive probe defers instead of deleting.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.