mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #5319] [MERGED] fix(nodes): sync "start after first connect" expiry so un-activated nodes do not reset it #5847
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#5847
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/5319
Author: @rqzbeh
Created: 6/14/2026
Status: ✅ Merged
Merged: 6/15/2026
Merged by: @MHSanaei
Base:
main← Head:fix/node-expiry-first-connect-sync📝 Commits (4)
6505ce7fix(nodes): stop un-activated nodes from resetting "start after first connect" expiry54fb2e6Merge branch 'main' into fix/node-expiry-first-connect-syncaf60c1dMerge branch 'main' into fix/node-expiry-first-connect-sync3898849fix(nodes): cast expiry merge params to BIGINT for Postgres📊 Changes
2 files changed (+173 additions, -4 deletions)
View changed files
📝
internal/web/service/inbound_node.go(+32 -4)➕
internal/web/service/node_client_expiry_sync_test.go(+141 -0)📄 Description
Summary
Fixes multi-node sync of the "start expiry after first connect" timer. A node where a client never connected was resetting the activated expiry deadline that another node had already started, so the main panel showed the timer "not started" and the subscription reported a wrong, perpetually-resetting expiry/usage.
Why
A user with inbounds spread across several nodes reported that traffic usage syncs between nodes but the expiry time does not: one node showed 28 days remaining (timer running) while the main panel still showed the full 30 days "not started", and the subscription's expiry/usage were wrong as a result.
Root cause:
client_trafficsrow —Emailisgorm:"unique"(internal/xray/client_traffic.go).expiryTimeis stored as a negative duration; each node converts it to an absolute deadline (now + duration) the first time the client connects on that node (adjustTrafficsininbound_traffic.go).setRemoteTrafficLockedininternal/web/service/inbound_node.go) wroteexpiry_time = ?unconditionally for every node sync. A node where the client never connected keeps reporting the un-activated negative value and overwrites the absolute deadline the active node had set — last writer wins, and the un-activated nodes keep re-asserting the negative value.internal/sub/service.go→subscriptionExpiryFromClient) reads that shared row and recomputes a negative value asnow + durationon every fetch, so the client's expiry never counts down and the usage shown is wrong.The fix
Guard the merge: an un-activated (
<= 0) value reported by a node can never reset an already-activated absolute deadline. A positive node value is still adopted unchanged, so a node that legitimately moves the deadline forward (traffic reset / auto-renew) still propagates — the guard only blocks the negative-clobbers-positive case that causes the bug.The rule is expressed both in the SQL
CASEused by the merge and a tinymergeActivationExpiryhelper kept in lockstep with it; the structural-change check reuses the helper so the guard doesn't cause spurious config re-pushes to nodes.Type of change
Areas affected
How was this tested?
go build ./...,go vet ./..., andgo test ./...all pass. New tests ininternal/web/service/node_client_expiry_sync_test.go, built on the existing node-merge harness (real SQLite DB):TestMergeActivationExpiry— the pure rule (master unset → take node; activation adopted over stored duration; un-activated/zero node value never resets an activated deadline; positive node value always adopted, incl. forward renewal).TestNodeFirstConnectExpiry_NotClobbered— end-to-end throughsetRemoteTrafficLocked: node 1 activates an absolute deadline; a later node-2 sync still reporting the negative duration must not reset it.TestNodeFirstConnectExpiry_NotClobbered_WithSettings— same, but snapshots carry real settings JSON, exercising theGetClients/SyncInboundbranch to prove that path doesn't re-derive the per-email expiry from the node's still-negative settings.TestNodeRenewExtendsExpiry— guards against over-correcting: a node that moves the deadline forward (auto-renew) still propagates to the master.All existing node-merge/traffic tests (
TestTwoNodesShareEmail_SumsCorrectly,TestInboundRemoval_KeepsSharedEmailRow,TestStatsUnderSiblingInbound_KeepsNodeBaseline,TestCentralReset_NoReAdd, …) still pass — traffic accounting is unchanged.Screenshots / recordings
N/A (backend-only).
Breaking changes
None. Only an un-activated (
<= 0) expiry reported by a node is prevented from overwriting an already-activated, positive deadline. Traffic accounting, auto-renew forward extensions, and the authoritative master→node config push are unchanged; the shared expiry row simply converges to the first activation instead of flip-flopping. No migration required.Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass. (No frontend changes.)🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.