[PR #6833] [MERGED] fix(traffic): re-enable quota-disabled clients on inbound and reset-all resets #6471

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6833
Author: @jayhemnani9910
Created: 10/15/2026
Status: ✅ Merged
Merged: 10/24/2026
Merged by: @MHSanaei

Base: main ← Head: fix/periodic-reset-reenable-clients


📝 Commits (1)

  • 290a5e7 fix(traffic): re-enable quota-disabled clients on inbound and reset-all resets

📊 Changes

7 files changed (+145 additions, -23 deletions)

View changed files

📝 internal/web/job/periodic_traffic_reset_client_test.go (+46 -1)
📝 internal/web/job/periodic_traffic_reset_job.go (+4 -1)
📝 internal/web/service/client_bulk_reset_reenable_test.go (+21 -0)
📝 internal/web/service/client_crud.go (+31 -3)
📝 internal/web/service/client_traffic.go (+37 -14)
📝 internal/web/service/mtproto_quota_reset_test.go (+2 -2)
📝 internal/web/service/node_reset_undelivered_test.go (+4 -2)

📄 Description

Summary

When a client runs out of quota, the inbound's periodic traffic reset and the Reset All Client Traffic button zero its usage but leave it switched off. This makes both paths re-enable the clients their quota switched off, the same way the per-client reset, bulk reset and the client's own reset cycle already do.

Why

Running out of quota switches a client off in three places: client_traffics.enable, the clients record (internal/web/service/inbound_disable.go:173) and the inbound settings JSON (inbound_disable.go:135). GetXrayConfig skips any client whose record is off (internal/web/service/xray.go:246).

ResetAllClientTraffics (used by the inbound's periodic reset, internal/web/job/periodic_traffic_reset_job.go:116) and ResetAllTraffics (the Reset All Client Traffic button) only set client_traffics.enable back to true (internal/web/service/client_traffic.go:177 and :222). The record and the settings JSON stay disabled. The client page then shows 0 usage, but the client is out of the running core until someone enables it by hand, every period.

Refs #4396: the same symptom on 3.0.2 with a daily inbound reset. It was closed after the reporter switched to expiry plus Auto Renew as a workaround, and it still reproduces on v3.10.2.

TestResetAllTrafficsReenablesDepletedClients already says a depleted client "must be re-enabled after Reset All Client Traffic, matching every other reset path", but it only checks client_traffics.

The fix reads which disabled clients had used up their quota inside the transaction that zeroes the counters, then switches those back on with BulkSetEnable after it commits. ResetAllClientTraffics now returns needRestart for the job. A client that is off while under its quota was disabled by hand and stays off. That is the same rule the client's own reset cycle uses (periodic_traffic_reset_job.go:154).

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

  • New tests:
    • TestPeriodicTrafficResetInboundRestoresClients (internal/web/job): a depleted client on an inbound with a daily reset comes back on in all three places; a client disabled by hand stays off.
    • TestResetAllTraffics_ReenablesDepletedClientEverywhere (internal/web/service): same two cases for Reset All Client Traffic.
    • Without the fix, both restore cases fail (clients.enable still false after the inbound's reset, client_records.enable = false, want true). With the fix they pass.
  • go test -shuffle=on -count=1 ./...: 50 packages ok, same as on main. golangci-lint on the two changed packages: 0 issues.
  • Manual check on the v3.10.2 release, panel and inbounds on 127.0.0.1:
    • Inbound A: VLESS TCP, traffic reset hourly, one client with a 30 KB limit.
    • Inbound B: traffic reset never, one client with a 30 KB limit and its own hourly reset.
    • I used up both clients' quota through a local Xray client, and both were cut off. After the 02:00 hourly run, client B was back on and could connect. Client A showed 0 usage but was still disabled (record and settings JSON) and could not connect.
    • Pressing Reset All Client Traffic on the used-up clients gave the same result as client A.
  • With this branch, Reset All Client Traffic brings both used-up clients back and they connect again. After the next hourly run, client A is back on too. A client disabled by hand on an hourly-reset inbound stays off.

Breaking changes

None.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass. (no frontend changes)
  • I updated the Wiki / README / API docs if user-facing behavior changed. (not needed)
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 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/6833 **Author:** [@jayhemnani9910](https://github.com/jayhemnani9910) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/24/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/periodic-reset-reenable-clients` --- ### 📝 Commits (1) - [`290a5e7`](https://github.com/MHSanaei/3x-ui/commit/290a5e742c5450c62c509a80460e5be32c26bb29) fix(traffic): re-enable quota-disabled clients on inbound and reset-all resets ### 📊 Changes **7 files changed** (+145 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/job/periodic_traffic_reset_client_test.go` (+46 -1) 📝 `internal/web/job/periodic_traffic_reset_job.go` (+4 -1) 📝 `internal/web/service/client_bulk_reset_reenable_test.go` (+21 -0) 📝 `internal/web/service/client_crud.go` (+31 -3) 📝 `internal/web/service/client_traffic.go` (+37 -14) 📝 `internal/web/service/mtproto_quota_reset_test.go` (+2 -2) 📝 `internal/web/service/node_reset_undelivered_test.go` (+4 -2) </details> ### 📄 Description ## Summary When a client runs out of quota, the inbound's periodic traffic reset and the **Reset All Client Traffic** button zero its usage but leave it switched off. This makes both paths re-enable the clients their quota switched off, the same way the per-client reset, bulk reset and the client's own reset cycle already do. ## Why Running out of quota switches a client off in three places: `client_traffics.enable`, the clients record (`internal/web/service/inbound_disable.go:173`) and the inbound settings JSON (`inbound_disable.go:135`). `GetXrayConfig` skips any client whose record is off (`internal/web/service/xray.go:246`). `ResetAllClientTraffics` (used by the inbound's periodic reset, `internal/web/job/periodic_traffic_reset_job.go:116`) and `ResetAllTraffics` (the Reset All Client Traffic button) only set `client_traffics.enable` back to true (`internal/web/service/client_traffic.go:177` and `:222`). The record and the settings JSON stay disabled. The client page then shows 0 usage, but the client is out of the running core until someone enables it by hand, every period. Refs #4396: the same symptom on 3.0.2 with a daily inbound reset. It was closed after the reporter switched to expiry plus Auto Renew as a workaround, and it still reproduces on v3.10.2. `TestResetAllTrafficsReenablesDepletedClients` already says a depleted client "must be re-enabled after Reset All Client Traffic, matching every other reset path", but it only checks `client_traffics`. The fix reads which disabled clients had used up their quota inside the transaction that zeroes the counters, then switches those back on with `BulkSetEnable` after it commits. `ResetAllClientTraffics` now returns `needRestart` for the job. A client that is off while under its quota was disabled by hand and stays off. That is the same rule the client's own reset cycle uses (`periodic_traffic_reset_job.go:154`). ## Type of change - [x] Bug fix - [ ] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [ ] Frontend (UI / panel pages) - [ ] Backend (API endpoints, login, settings) - [ ] Xray config generation - [ ] Subscription (share links / Clash / JSON) - [x] Statistics / traffic counters - [ ] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [ ] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? - New tests: - `TestPeriodicTrafficResetInboundRestoresClients` (`internal/web/job`): a depleted client on an inbound with a daily reset comes back on in all three places; a client disabled by hand stays off. - `TestResetAllTraffics_ReenablesDepletedClientEverywhere` (`internal/web/service`): same two cases for Reset All Client Traffic. - Without the fix, both restore cases fail (`clients.enable still false after the inbound's reset`, `client_records.enable = false, want true`). With the fix they pass. - `go test -shuffle=on -count=1 ./...`: 50 packages ok, same as on main. golangci-lint on the two changed packages: 0 issues. - Manual check on the v3.10.2 release, panel and inbounds on 127.0.0.1: - Inbound A: VLESS TCP, traffic reset `hourly`, one client with a 30 KB limit. - Inbound B: traffic reset `never`, one client with a 30 KB limit and its own `hourly` reset. - I used up both clients' quota through a local Xray client, and both were cut off. After the 02:00 hourly run, client B was back on and could connect. Client A showed 0 usage but was still disabled (record and settings JSON) and could not connect. - Pressing Reset All Client Traffic on the used-up clients gave the same result as client A. - With this branch, Reset All Client Traffic brings both used-up clients back and they connect again. After the next hourly run, client A is back on too. A client disabled by hand on an hourly-reset inbound stays off. ## Breaking changes None. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [ ] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. (no frontend changes) - [ ] I updated the Wiki / README / API docs if user-facing behavior changed. (not needed) - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:09:01 +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#6471
No description provided.