[PR #6962] [MERGED] fix(traffic): restore quota-disabled inbounds when their traffic is reset #6545

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6962
Author: @muditagrawal2007
Created: 10/26/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @MHSanaei

Base: main ← Head: fix/inbound-reset-restores-quota-disabled-inbounds


📝 Commits (3)

  • af66e5e fix(traffic): restore quota-disabled inbounds when their traffic is reset
  • cb84245 Merge remote-tracking branch 'origin/main' into pr/6962
  • 6af63b3 style(traffic): keep the inbound reset comments to two lines

📊 Changes

9 files changed (+184 additions, -38 deletions)

View changed files

📝 internal/web/controller/inbound.go (+6 -4)
📝 internal/web/job/periodic_traffic_reset_job.go (+3 -19)
📝 internal/web/service/api_scale_postgres_test.go (+2 -2)
📝 internal/web/service/inbound_disable.go (+24 -0)
📝 internal/web/service/inbound_traffic.go (+43 -10)
➕ internal/web/service/inbound_traffic_restore_test.go (+103 -0)
📝 internal/web/service/mtproto_quota_reset_test.go (+1 -1)
📝 internal/web/service/node_admin_fanout_test.go (+1 -1)
📝 internal/web/service/reset_writer_test.go (+1 -1)

📄 Description

The bug

An inbound with a traffic cap is switched off by disableInvalidInbounds once up + down >= total, and it is dropped from the running core — every client on it goes down with it.

The periodic reset brought such an inbound back: after zeroing its counters it re-enabled it (SetInboundEnable). The admin reset endpoints did not:

  • POST /panel/api/inbounds/:id/resetTraffic
  • POST /panel/api/inbounds/resetAllTraffics

They only zeroed up/down and left enable = false. The inbound then stayed off permanently:

  • the periodic job could not recognise it either — its inboundQuotaDisabled predicate needs up + down >= total, which the reset had just made false;
  • the inbound's cap no longer applied, yet nothing brought it back;
  • the only recovery was toggling the inbound by hand in the UI.

So an operator whose inbound hit its cap, and who clicked "Reset All Traffic" expecting service to resume, silently killed every client on that inbound for good.

The fix

The "a traffic cap switched this inbound off" predicate moves into the service layer (internal/web/service/inbound_disable.go), next to the disableInvalidInbounds it mirrors, and is applied by both reset paths:

  • ResetInboundTraffic re-enables the inbound when its own cap was what switched it off;
  • ResetAllTraffics does the same for every inbound it just unblocked.

Only a cap may bring an inbound back. Inbounds an operator switched off by hand and inbounds that expired stay off — the reset has nothing to do with either, and the periodic job already drew that line.

The periodic job loses its own copy of the predicate and relies on the service, so there is one definition of "quota-disabled" instead of two.

Both reset methods now report whether the running core still needs a restart, so a plain counter reset no longer restarts Xray for nothing — the re-enable patches the live core in place, and only a failed patch asks for a restart.

Tests

internal/web/service/inbound_traffic_restore_test.go drives the real code path against a temp DB and a local runtime:

  • TestResetAllTrafficsRestoresQuotaDisabledInbound
  • TestResetInboundTrafficRestoresQuotaDisabledInbound
  • TestResetAllTrafficsLeavesHandDisabledAndExpiredInboundsOff — the guard that the fix does not bring back inbounds it should not.

The first two fail on the unfixed tree with "an inbound whose traffic cap was lifted must be enabled again"; the third passes before and after, so it pins the boundary rather than the fix.

go test ./..., golangci-lint run and make gen-check are green.


🔄 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/6962 **Author:** [@muditagrawal2007](https://github.com/muditagrawal2007) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/inbound-reset-restores-quota-disabled-inbounds` --- ### 📝 Commits (3) - [`af66e5e`](https://github.com/MHSanaei/3x-ui/commit/af66e5e28c4995b7be57fb8b2b8dd8eb1a28576b) fix(traffic): restore quota-disabled inbounds when their traffic is reset - [`cb84245`](https://github.com/MHSanaei/3x-ui/commit/cb842453179b86eea02f387e70e6dc4f1bf0a9bc) Merge remote-tracking branch 'origin/main' into pr/6962 - [`6af63b3`](https://github.com/MHSanaei/3x-ui/commit/6af63b3e6a7d04508255fdaba670918af9ae806f) style(traffic): keep the inbound reset comments to two lines ### 📊 Changes **9 files changed** (+184 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/controller/inbound.go` (+6 -4) 📝 `internal/web/job/periodic_traffic_reset_job.go` (+3 -19) 📝 `internal/web/service/api_scale_postgres_test.go` (+2 -2) 📝 `internal/web/service/inbound_disable.go` (+24 -0) 📝 `internal/web/service/inbound_traffic.go` (+43 -10) ➕ `internal/web/service/inbound_traffic_restore_test.go` (+103 -0) 📝 `internal/web/service/mtproto_quota_reset_test.go` (+1 -1) 📝 `internal/web/service/node_admin_fanout_test.go` (+1 -1) 📝 `internal/web/service/reset_writer_test.go` (+1 -1) </details> ### 📄 Description ## The bug An inbound with a traffic cap is switched off by `disableInvalidInbounds` once `up + down >= total`, and it is dropped from the running core — every client on it goes down with it. The **periodic** reset brought such an inbound back: after zeroing its counters it re-enabled it (`SetInboundEnable`). The **admin** reset endpoints did not: - `POST /panel/api/inbounds/:id/resetTraffic` - `POST /panel/api/inbounds/resetAllTraffics` They only zeroed `up`/`down` and left `enable = false`. The inbound then stayed off **permanently**: - the periodic job could not recognise it either — its `inboundQuotaDisabled` predicate needs `up + down >= total`, which the reset had just made false; - the inbound's cap no longer applied, yet nothing brought it back; - the only recovery was toggling the inbound by hand in the UI. So an operator whose inbound hit its cap, and who clicked "Reset All Traffic" expecting service to resume, silently killed every client on that inbound for good. ## The fix The "a traffic cap switched this inbound off" predicate moves into the service layer (`internal/web/service/inbound_disable.go`), next to the `disableInvalidInbounds` it mirrors, and is applied by both reset paths: - `ResetInboundTraffic` re-enables the inbound when its own cap was what switched it off; - `ResetAllTraffics` does the same for every inbound it just unblocked. Only a cap may bring an inbound back. Inbounds an operator switched off **by hand** and inbounds that **expired** stay off — the reset has nothing to do with either, and the periodic job already drew that line. The periodic job loses its own copy of the predicate and relies on the service, so there is one definition of "quota-disabled" instead of two. Both reset methods now report whether the running core still needs a restart, so a plain counter reset no longer restarts Xray for nothing — the re-enable patches the live core in place, and only a failed patch asks for a restart. ## Tests `internal/web/service/inbound_traffic_restore_test.go` drives the real code path against a temp DB and a local runtime: - `TestResetAllTrafficsRestoresQuotaDisabledInbound` - `TestResetInboundTrafficRestoresQuotaDisabledInbound` - `TestResetAllTrafficsLeavesHandDisabledAndExpiredInboundsOff` — the guard that the fix does not bring back inbounds it should not. The first two fail on the unfixed tree with *"an inbound whose traffic cap was lifted must be enabled again"*; the third passes before and after, so it pins the boundary rather than the fix. `go test ./...`, `golangci-lint run` and `make gen-check` are green. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi changed title from [PR #6962] fix(traffic): restore quota-disabled inbounds when their traffic is reset to [PR #6962] [MERGED] fix(traffic): restore quota-disabled inbounds when their traffic is reset 2026-11-07 14:33:54 +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#6545
No description provided.