mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6263] [MERGED] fix(traffic): clear cross-panel rows only for clients actually renewed #6201
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#6201
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/6263
Author: @n0ctal
Created: 8/19/2026
Status: ✅ Merged
Merged: 8/22/2026
Merged by: @MHSanaei
Base:
main← Head:upstream-renew-clears-unrenewed📝 Commits (1)
570f2c5fix(traffic): clear cross-panel rows only for clients actually renewed📊 Changes
2 files changed (+113 additions, -2 deletions)
View changed files
➕
internal/web/service/inbound_autorenew_globaltraffic_test.go(+107 -0)📝
internal/web/service/inbound_traffic.go(+6 -2)📄 Description
Summary
autoRenewClientsdeletes a client'sclient_global_trafficsrows when it rolls the client into a fresh window. It was passing the full candidate list toclearGlobalTraffic, not the clients it actually renewed.Why this matters
The function collects every expired client that carries a reset interval, then skips three kinds of candidate before touching their counters:
renewals == 0),newExpiryTimeis still in the past onceResetMaxtruncates the catch-up.All three deliberately keep both their counters and their expiry — the third is exactly what
TestAutoRenewClients_TruncatedCatchUpLeavesTheClientDisabledpins down.Their cross-panel rows were dropped anyway, so the pushed totals and the local counters describe different windows. The damage is bounded and I want to state it accurately rather than oversell it:
PushGlobalClientTrafficsupserts, so the next push recreates the row, anddepletedClientsCondtrips on itsexpiry_time <= ?branch for all three cases, sodisableInvalidClientsstill cuts these clients in the same tick — nothing is served past its limit. What remains is a cross-panel under-report between the delete and the next push, repeated on every poll for as long as the client stays a candidate, because its expiry never advances.Scope
One argument in
internal/web/service/inbound_traffic.go: collect the emails whoseUp/Downthis pass zeroed, and hand those toclearGlobalTraffic. The renewed count returned to the caller now counts the same set — it was returning the candidate count, which the caller logs as"%v clients renewed".No change to when a client is renewed, to the reset cap, or to the delete itself.
clearGlobalTrafficalready early-returns on an empty slice, so a poll that renews nobody remains a no-op instead of deleting every row — worth stating because the new list can be empty where the old one never was.Validation
go build ./...,go vet ./internal/...and the fullinternal/web/servicesuite pass.Two new tests, both driven through
autoRenewClientsitself:TestAutoRenewClients_TruncatedCatchUpKeepsCrossPanelTraffic— a capped catch-up keeps its rows. Fails on the previous behaviour withcross-panel rows=0, want 1; it also asserts the local counters survived, so the test cannot pass by accident if that scenario ever stops exercising the cap.TestAutoRenewClients_RenewedClientLosesCrossPanelTraffic— a genuinely renewed client still loses its rows. This one passes both before and after by design: it is the guard against "fixing" the report by dropping the delete altogether.Risk
Low. The only behavioural difference is that clients which were not renewed keep rows that were previously deleted, and the debug count now matches what the function did. Renewed clients are unaffected, so the reason the delete exists — stale pushed totals re-depleting a fresh window — still holds.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.