mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #5614] [MERGED] fix(runtime): refresh cached node remotes on identity change #5930
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#5930
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/5614
Author: @n0ctal
Created: 6/27/2026
Status: ✅ Merged
Merged: 6/28/2026
Merged by: @MHSanaei
Base:
main← Head:upstream-c-remote-cache-convergence📝 Commits (4)
060fad5fix(runtime): refresh cached node remotes on identity changec8565a8Merge branch 'main' into upstream-c-remote-cache-convergence1fae610Merge branch 'main' into upstream-c-remote-cache-convergence64053e0Merge branch 'main' into upstream-c-remote-cache-convergence📊 Changes
2 files changed (+162 additions, -3 deletions)
View changed files
📝
internal/web/runtime/manager.go(+40 -3)➕
internal/web/runtime/manager_convergence_test.go(+122 -0)📄 Description
Summary
Manager.RemoteForcaches one*Remoteper node id and returns the cached instance on every later call, keyed only onnode.Id. If a node's connection identity changes (address, port, base path, scheme, API token, TLS verify mode, pinned cert, egress/outbound tag, allow-private), the cachedRemotekeeps using the stale identity until the process restarts or the entry is explicitly invalidated. This PR makes the cache converge: a cached remote whose identity no longer matches the requested node is transparently replaced.Why
A node's identity can change at runtime (token rotation, address/port move, switching TLS verify mode, repinning a cert). With the id-only cache, the master can keep talking to a worker with an old token or old address after the operator has already changed it — silently, with no error, until a restart. That is both a correctness bug (config changes don't take effect) and a security gap (a rotated-out token stays live in the cached path). Convergence on identity change closes both.
Scope
internal/web/runtime/manager.go:RemoteFornow compares the cached remote's identity against the requested node viasameRemoteIdentity. On a match it returns the cached instance (fast path underRLock); on a mismatch it rebuilds the remote under the write lock and replaces the map entry. Standard double-checked locking — no network I/O is performed under the lock.sameRemoteIdentitycompares exactly the fields that affect how we connect/authenticate:Id, Scheme, Address, Port, BasePath, ApiToken, AllowPrivateAddress, TlsVerifyMode, PinnedCertSha256, OutboundTag. Display/metrics fields are intentionally excluded so cosmetic edits don't churn the cache.cloneRemoteNodestores a defensive copy of the node in the cache (deep-copyingInboundTags) so later mutation of the caller's*Nodecannot retroactively change the cached identity and mask a real divergence.Tests:
manager_convergence_test.gocovers same-identity cache hit (no rebuild), each identity-field change forcing a rebuild, and the no-churn case for display fields.Validation
go test ./internal/web/runtime -run 'Convergence|RemoteFor|Identity|Refresh'— greengo test -race ./internal/web/runtime -run 'Convergence|RemoteFor|Identity|Refresh'— greengo vet ./internal/web/runtime— cleanRisk
Low. Behavior is unchanged when a node's identity is unchanged (same cached instance returned). The only new behavior is that an identity change now produces a fresh remote instead of reusing a stale one; any in-flight request on the old instance completes normally and the old remote is GC'd. No public API or schema change.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.