[PR #6263] [MERGED] fix(traffic): clear cross-panel rows only for clients actually renewed #6201

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

📋 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)

  • 570f2c5 fix(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

autoRenewClients deletes a client's client_global_traffics rows when it rolls the client into a fresh window. It was passing the full candidate list to clearGlobalTraffic, 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:

  • the email is not present in the inbound's settings,
  • the catch-up resolves to no whole interval (renewals == 0),
  • newExpiryTime is still in the past once ResetMax truncates the catch-up.

All three deliberately keep both their counters and their expiry — the third is exactly what TestAutoRenewClients_TruncatedCatchUpLeavesTheClientDisabled pins 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: PushGlobalClientTraffics upserts, so the next push recreates the row, and depletedClientsCond trips on its expiry_time <= ? branch for all three cases, so disableInvalidClients still 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 whose Up/Down this pass zeroed, and hand those to clearGlobalTraffic. 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.

clearGlobalTraffic already 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 full internal/web/service suite pass.

Two new tests, both driven through autoRenewClients itself:

  • TestAutoRenewClients_TruncatedCatchUpKeepsCrossPanelTraffic — a capped catch-up keeps its rows. Fails on the previous behaviour with cross-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.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6263 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 8/19/2026 **Status:** ✅ Merged **Merged:** 8/22/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `upstream-renew-clears-unrenewed` --- ### 📝 Commits (1) - [`570f2c5`](https://github.com/MHSanaei/3x-ui/commit/570f2c5843208bed9727c865bc1240c713d8a111) fix(traffic): clear cross-panel rows only for clients actually renewed ### 📊 Changes **2 files changed** (+113 additions, -2 deletions) <details> <summary>View changed files</summary> ➕ `internal/web/service/inbound_autorenew_globaltraffic_test.go` (+107 -0) 📝 `internal/web/service/inbound_traffic.go` (+6 -2) </details> ### 📄 Description ## Summary `autoRenewClients` deletes a client's `client_global_traffics` rows when it rolls the client into a fresh window. It was passing the full *candidate* list to `clearGlobalTraffic`, 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: - the email is not present in the inbound's settings, - the catch-up resolves to no whole interval (`renewals == 0`), - `newExpiryTime` is still in the past once `ResetMax` truncates the catch-up. All three deliberately keep both their counters and their expiry — the third is exactly what `TestAutoRenewClients_TruncatedCatchUpLeavesTheClientDisabled` pins 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: `PushGlobalClientTraffics` upserts, so the next push recreates the row, and `depletedClientsCond` trips on its `expiry_time <= ?` branch for all three cases, so `disableInvalidClients` still 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 whose `Up`/`Down` this pass zeroed, and hand those to `clearGlobalTraffic`. 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. `clearGlobalTraffic` already 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 full `internal/web/service` suite pass. Two new tests, both driven through `autoRenewClients` itself: - `TestAutoRenewClients_TruncatedCatchUpKeepsCrossPanelTraffic` — a capped catch-up keeps its rows. Fails on the previous behaviour with `cross-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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:07:04 +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#6201
No description provided.