[PR #5477] [MERGED] fix: resolve a batch of open bug-tagged issues (traffic accounting, share strategy, sub address, CPU) #5892

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5477
Author: @MHSanaei
Created: 6/21/2026
Status: ✅ Merged
Merged: 6/21/2026
Merged by: @MHSanaei

Base: main ← Head: fix/open-bug-issues-sweep


📝 Commits (5)

  • e59788b fix(node): never re-add a node's full counter on reset/restart (#5456, #5476, #5390)
  • a0ea9c9 fix(inbound): keep persisted node share strategy on edit (#5375)
  • 6a7495e <3
  • 8b6cceb perf(traffic): skip cross-panel quota subquery when no globals exist (#5392, #5389)
  • 837300b fix(sub): don't advertise a leaked client IP for local wildcard inbounds (#5425)

📊 Changes

26 files changed (+248 additions, -44 deletions)

View changed files

📝 frontend/src/pages/inbounds/InboundsPage.tsx (+2 -1)
📝 frontend/src/pages/inbounds/form/InboundFormModal.tsx (+11 -1)
📝 frontend/src/test/inbound-form-modal.test.tsx (+52 -1)
📝 internal/database/index_tags_test.go (+2 -1)
📝 internal/database/model/client_global_traffic.go (+1 -1)
📝 internal/sub/build_urls_test.go (+25 -0)
📝 internal/sub/service.go (+10 -4)
📝 internal/web/service/client_traffic.go (+15 -1)
📝 internal/web/service/global_traffic_test.go (+26 -0)
📝 internal/web/service/inbound_disable.go (+23 -2)
📝 internal/web/service/inbound_node.go (+2 -2)
📝 internal/web/service/inbound_traffic.go (+8 -2)
📝 internal/web/service/node_client_traffic_sum_test.go (+46 -3)
📝 internal/web/translation/ar-EG.json (+2 -2)
📝 internal/web/translation/en-US.json (+1 -1)
📝 internal/web/translation/es-ES.json (+2 -2)
📝 internal/web/translation/fa-IR.json (+2 -2)
📝 internal/web/translation/id-ID.json (+2 -2)
📝 internal/web/translation/ja-JP.json (+2 -2)
📝 internal/web/translation/pt-BR.json (+2 -2)

...and 6 more files

📄 Description

Sweep of open bug-tagged issues. Each fix is a self-contained commit with tests; full backend (service/sub/database) and all 569 frontend tests pass.

Fixes

Node traffic accounting — fix(node)

Fixes #5456, #5476, #5390

When a node's per-client counter dipped below the master's stored baseline (node reboot, xray restart, or a reset propagated to the node), the delta accounting clamped delta to the node's whole current counter and re-added it to the master total — double-counting a client's lifetime usage in a single sync and often pushing them over quota. Now a backward-moving counter is treated as a reset: add 0 and rebaseline.

Resets also clear the per-node NodeClientTraffic baseline (ResetClientTrafficByEmail, resetClientTrafficLocked, BulkResetTraffic, resetAllClientTrafficsLocked), so a node's pre-reset cumulative — including traffic it counted but had not yet synced — can't leak back after a reset ("reset reverts after a while").

Share address strategy race — fix(inbound)

Fixes #5375

Opening the edit modal silently reverted shareAddrStrategy from node to listen: the downgrade effect fired before the form settled (availableNodes empty until /nodes/list resolves, and Form.useWatch('protocol') briefly empty on first edit render). Gated the downgrade on the nodes list being fetched and the protocol watch being settled.

Hot query CPU — perf(traffic)

Fixes #5392, #5389

disableInvalidClients ran a correlated EXISTS against client_global_traffics over the full client_traffics table every 5s, pegging Postgres at 100% CPU on large client counts. On a panel no master pushes to, that table is empty, so the branch can never match — probe first and drop it (common case), and add idx_client_global_email for when globals are present. This also relieves the "traffic writer queue full" freeze (#5389), since the heavy query runs inside the serialized traffic write. Cross-panel enforcement is unchanged.

Subscription address — fix(sub)

Fixes #5425

For a local inbound with no node, no custom share address, and a wildcard/blank listen, resolveInboundAddress fell through to the subscriber's request host — which behind NAT/proxy/CDN can be the requesting client's own IP, so the subscription advertised the client's address. Now prefer the admin's configured Sub/Web domain over the raw request host for that last-resort fallback. Single-domain setups (no configured host) are unaffected.

Notes

  • Already-fixed/by-design issues from the same sweep were closed separately: #5434 (fixed by #5352), #5402 (by-design).
  • #5297 was reviewed but left for ongoing investigation per the maintainer note.

🔄 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/5477 **Author:** [@MHSanaei](https://github.com/MHSanaei) **Created:** 6/21/2026 **Status:** ✅ Merged **Merged:** 6/21/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/open-bug-issues-sweep` --- ### 📝 Commits (5) - [`e59788b`](https://github.com/MHSanaei/3x-ui/commit/e59788bac16662fb5d3df036358aca187f212d7b) fix(node): never re-add a node's full counter on reset/restart (#5456, #5476, #5390) - [`a0ea9c9`](https://github.com/MHSanaei/3x-ui/commit/a0ea9c9f454c92d22ebce0c8a5d22f3f2810161c) fix(inbound): keep persisted node share strategy on edit (#5375) - [`6a7495e`](https://github.com/MHSanaei/3x-ui/commit/6a7495ebea3eacdf18ef36ad2624f4ef4fc886e9) <3 - [`8b6cceb`](https://github.com/MHSanaei/3x-ui/commit/8b6ccebfb09f7be41e63e6493a770d41f94ae842) perf(traffic): skip cross-panel quota subquery when no globals exist (#5392, #5389) - [`837300b`](https://github.com/MHSanaei/3x-ui/commit/837300b12730a28697546121345d7ec042ba6652) fix(sub): don't advertise a leaked client IP for local wildcard inbounds (#5425) ### 📊 Changes **26 files changed** (+248 additions, -44 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/pages/inbounds/InboundsPage.tsx` (+2 -1) 📝 `frontend/src/pages/inbounds/form/InboundFormModal.tsx` (+11 -1) 📝 `frontend/src/test/inbound-form-modal.test.tsx` (+52 -1) 📝 `internal/database/index_tags_test.go` (+2 -1) 📝 `internal/database/model/client_global_traffic.go` (+1 -1) 📝 `internal/sub/build_urls_test.go` (+25 -0) 📝 `internal/sub/service.go` (+10 -4) 📝 `internal/web/service/client_traffic.go` (+15 -1) 📝 `internal/web/service/global_traffic_test.go` (+26 -0) 📝 `internal/web/service/inbound_disable.go` (+23 -2) 📝 `internal/web/service/inbound_node.go` (+2 -2) 📝 `internal/web/service/inbound_traffic.go` (+8 -2) 📝 `internal/web/service/node_client_traffic_sum_test.go` (+46 -3) 📝 `internal/web/translation/ar-EG.json` (+2 -2) 📝 `internal/web/translation/en-US.json` (+1 -1) 📝 `internal/web/translation/es-ES.json` (+2 -2) 📝 `internal/web/translation/fa-IR.json` (+2 -2) 📝 `internal/web/translation/id-ID.json` (+2 -2) 📝 `internal/web/translation/ja-JP.json` (+2 -2) 📝 `internal/web/translation/pt-BR.json` (+2 -2) _...and 6 more files_ </details> ### 📄 Description Sweep of open `bug`-tagged issues. Each fix is a self-contained commit with tests; full backend (`service`/`sub`/`database`) and all 569 frontend tests pass. ## Fixes ### Node traffic accounting — `fix(node)` Fixes #5456, #5476, #5390 When a node's per-client counter dipped below the master's stored baseline (node reboot, xray restart, or a reset propagated to the node), the delta accounting clamped `delta` to the node's whole current counter and **re-added it** to the master total — double-counting a client's lifetime usage in a single sync and often pushing them over quota. Now a backward-moving counter is treated as a reset: add `0` and rebaseline. Resets also clear the per-node `NodeClientTraffic` baseline (`ResetClientTrafficByEmail`, `resetClientTrafficLocked`, `BulkResetTraffic`, `resetAllClientTrafficsLocked`), so a node's pre-reset cumulative — including traffic it counted but had not yet synced — can't leak back after a reset ("reset reverts after a while"). ### Share address strategy race — `fix(inbound)` Fixes #5375 Opening the edit modal silently reverted `shareAddrStrategy` from `node` to `listen`: the downgrade effect fired before the form settled (`availableNodes` empty until `/nodes/list` resolves, and `Form.useWatch('protocol')` briefly empty on first edit render). Gated the downgrade on the nodes list being fetched and the protocol watch being settled. ### Hot query CPU — `perf(traffic)` Fixes #5392, #5389 `disableInvalidClients` ran a correlated `EXISTS` against `client_global_traffics` over the full `client_traffics` table every 5s, pegging Postgres at 100% CPU on large client counts. On a panel no master pushes to, that table is empty, so the branch can never match — probe first and drop it (common case), and add `idx_client_global_email` for when globals are present. This also relieves the "traffic writer queue full" freeze (#5389), since the heavy query runs inside the serialized traffic write. Cross-panel enforcement is unchanged. ### Subscription address — `fix(sub)` Fixes #5425 For a local inbound with no node, no custom share address, and a wildcard/blank listen, `resolveInboundAddress` fell through to the subscriber's request host — which behind NAT/proxy/CDN can be the requesting client's own IP, so the subscription advertised the client's address. Now prefer the admin's configured Sub/Web domain over the raw request host for that last-resort fallback. Single-domain setups (no configured host) are unaffected. ## Notes - Already-fixed/by-design issues from the same sweep were closed separately: #5434 (fixed by #5352), #5402 (by-design). - #5297 was reviewed but left for ongoing investigation per the maintainer note. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:50 +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#5892
No description provided.