mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #6987] [MERGED] Re-enable depleted clients on renewal, and stop operator writes queueing behind the 5s poll and node merges #6565
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#6565
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/6987
Author: @Zaltapar
Created: 10/28/2026
Status: ✅ Merged
Merged: 11/5/2026
Merged by: @MHSanaei
Base:
main← Head:fix/renewal-reenable-and-faster-saves📝 Commits (5)
10e6baafix(clients): re-enable depleted clients when a renewal restores their limitse675723perf(clients): fold the reset re-enable into the reset and serve operator writes ahead of the 5s poll and node merges01136c8fix(clients): re-enable every inbound on reset, and drain both writer lanes on stop5403b0dfix(clients): preserve manual disables when integrating renewal fixesc3ee71aMerge remote-tracking branch 'origin/main' into codex/review-pr-6987-20261105📊 Changes
13 files changed (+684 additions, -92 deletions)
View changed files
📝
internal/web/service/client_crud.go(+15 -0)📝
internal/web/service/client_inbound_apply.go(+28 -1)➕
internal/web/service/client_renewal_reenable.go(+60 -0)📝
internal/web/service/client_traffic.go(+15 -10)📝
internal/web/service/client_traffic_reset_order_test.go(+1 -1)➕
internal/web/service/client_update_reenable_test.go(+284 -0)📝
internal/web/service/inbound_disable.go(+42 -0)📝
internal/web/service/inbound_node.go(+3 -1)📝
internal/web/service/inbound_traffic.go(+64 -47)📝
internal/web/service/inbound_traffic_global.go(+1 -1)📝
internal/web/service/traffic_writer.go(+74 -19)📝
internal/web/service/traffic_writer_test.go(+95 -11)📝
internal/web/service/tuic_traffic_receipt.go(+2 -1)📄 Description
Summary
Two fixes for the renewal workflow on a VPN reseller panel:
Why
When a client exhausts its traffic or its duration, the enforcement loop disables it in all three stores (inbound settings JSON,
client_traffics,clients) and drops the user from the running core.bulkAdjustalready re-enabled such a client when the adjustment lifted it back within limits (#5619), and a traffic reset re-enabled it too — but only by running a second, full client update behind the reset.Renewing the client from the client editor (or via the single-field renewal endpoints the Telegram bot uses: set expiry / set traffic limit) left it disabled: the update wrote the fresh expiry/quota but kept the off switch, so the operator had to flip the enable switch by hand. This is the same gap as #5619 on the paths that endpoint covers.
The renewal actions were also slow: a reset of one client on N inbounds cost N serialized write slots for the counters and N more for the follow-up full update (N inbound JSON rewrites, N stat-row re-assertions, N runtime adds). On a node-heavy panel every one of those writes could additionally wait behind the next batch of 5s traffic polls / node snapshot merges in the single serial writer (#6035), so a save or reset "took so much time".
Type of change
Areas affected
Changes
Re-enable on renewal (
fix(clients)) — the #5619 set-difference rule applied to the renewal paths that still lacked it:ClientService.renewalReenables: the client's enforcement row must carry the off switch AND match the production depletion predicate (including a fresh cross-panel push, exactly as the loop itself reads it), and the post-update total/expiry must clear the depletion (projected against the current usage and the pushed usage; usage is untouched by an update). A client the operator disabled while it was still within its limits, or one still depleted after the update, stays off.ClientService.Update(the editor save andPOST /clients/update/:email, local and node inbounds alike) forcesenableon in that case; the existing per-inbound apply then flips the JSON entry, theclient_trafficsrow and theclientsrecord and re-adds the user on the running core (or pushes the node), so the re-enable lands in all stores at once.enableflag — only the inbound path ever wrote it before.ResetClientExpiryTimeByEmail/ResetClientTrafficLimitByEmail(Telegram bot renewals) flip the stored entry back on with the renewal instead of leaving it off.A note on the
enableoverride: the guard cannot distinguish anenable:falsethe editor round-tripped from one a caller chose deliberately, so a renewal that clears the depletion turns the client on even when the request carriesenable:false(the editor always round-trips the stored value, which is off for a quota-disabled client). This matches the panel-wide invariant that a client back within its limits is on — the same onebulkAdjust, the traffic resets and the calendar auto-renew already implement (#5619). A caller who wants a renewed client to stay off (e.g. payment not cleared yet) must disable it again after the renewal; nothing in the request or response reports the override, which is a known trade-off of this rule.Faster renewal actions (
perf(clients)):InboundService.resetClientTrafficLockednow flips this inbound's stored entry and the shared client record back on in the reset's own transaction (the re-enable twin of the disable pass'smarkClientsDisabledInSettings), re-adds the user on a local core, and marks the node dirty on a node inbound. The flip is decided per stored entry, not from the shared enforcement row: the first inbound's reset turns that row back on, and a row-keyed check would leave every sibling inbound's off entry stale, cutting the client off there until a full client update.ClientService.ResetTrafficByEmailonly still runs the follow-up full update when the resets left the record off (an inbound-less client, or a record no inbound hosted) — the common renewal case drops N serialized writes, N JSON rewrites and N runtime adds.c5d31de4e) but now serves two lanes — panel-initiated writes jump queued traffic-poll and node-merge work, so a save or reset on a node-heavy panel no longer waits on the next batch of 5s snapshots (#6035). Within each lane the order stays FIFO; on stop the drain empties both lanes, so no queued write is dropped.How was this tested?
client_update_reenable_test.go: an expired client extended in the editor comes back on in all three stores; a raised quota does the same; an extension that still lands in the past / a quota still below usage / a manual switch-off of a not-depleted client / a fresh cross-panel push above the new quota all stay disabled; the no-inbound case re-asserts the enforcement row; both single-field setters re-enable and both respect a manual disable; and a multi-inbound client comes back on every inbound after a reset (the per-entry flip).TestResetTrafficOfDepletedClientSurvivesTickMidResetkeeps proving that a tick landing mid-reset cannot re-disable the client (all three stores read enabled at 0 afterwards).TestTrafficWriterAdminLanePreemptsBackgroundQueue: with both lanes filled, the admin write is served before the background one.TestTrafficWriterStopDrainsEveryQueuedWrite: a stop drains every queued write on both lanes.TestTrafficResetKeepsTheReverseTag(and the reverse-tag suite) keep proving the drift case — entry on, enforcement row off — still plans the runtime re-add, which is what rebuilds a reverse tag on reset.internal/web/service,internal/web/runtime,internal/web/job,internal/web/controllersuites pass, plus a-racerun over the same packages, and a full-package run of thego-testgate.postgres-durable-firstandpostgres-migrationfrom.github/workflows/ci.yml) pass locally against a UTF8 Postgres 17 instance. (Note for anyone reproducing on Windows: the server must be created withinitdb -E UTF8— a locale-encoded database makes thepgx-based tests fail with "simple protocol queries must be run with client_encoding=UTF8" before they even connect to the panel's schema.)racegate passes locally over the touched packages; thefuzz-smokegate (both fuzzers, 30s) and the pinnedgolangci-lintv2.15.0 pass over the whole repo.node-e2ecannot run on the local Windows-on-ARM machine, so it — along with the whole fork-PR CI suite — is validated when a maintainer approves the workflow run.Breaking changes
None. Renewal re-enabling is strictly the set-difference the bulk paths already promised; manually disabled clients and still-depleted renewals are untouched. The one behavior change is documented above: a renewal that clears the depletion takes precedence over a round-tripped
enable:false.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
[PR #6987] Re-enable depleted clients on renewal, and stop operator writes queueing behind the 5s poll and node mergesto [PR #6987] [MERGED] Re-enable depleted clients on renewal, and stop operator writes queueing behind the 5s poll and node merges