mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #5684] [MERGED] fix(wireguard): build peers in GenXrayInboundConfig so node reconcile keeps clients #5960
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#5960
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/5684
Author: @STRENCH0
Created: 6/30/2026
Status: ✅ Merged
Merged: 7/8/2026
Merged by: @MHSanaei
Base:
main← Head:fix/wireguard-node-reconcile-peers📝 Commits (2)
0072f8afix(wireguard): build peers in GenXrayInboundConfig so node reconcile keeps clients34119e0Merge branch 'main' into fix/wireguard-node-reconcile-peers📊 Changes
3 files changed (+177 additions, -14 deletions)
View changed files
📝
internal/database/model/model.go(+79 -0)➕
internal/database/model/model_wireguard_peers_test.go(+97 -0)📝
internal/web/service/xray.go(+1 -14)📄 Description
Adding a WireGuard client on the master broke every WireGuard connection on the sub-node until Xray was manually restarted on the node. Adding the same client directly on the node worked.
Root cause: the panel stores WireGuard clients under the settings key
clients(the shape every other protocol uses), but xray-core's wireguard inbound is configured withpeers. Theclients->peersconversion lived only in the full-config generation path (XrayService.GetXrayConfig), which runs on a full Xray restart. The live gRPC AddInbound path goes through (*Inbound).GenXrayInboundConfig, which passed the WireGuard settings verbatimclientsand nopeers.Why the master path broke it and the node path did not:
Fix: Convert WireGuard
clientstopeersinGenXrayInboundConfigitself, the singlechokepoint for every live AddInbound (create, edit, node reconcile). Clients are the
source of truth:
WireguardClientsToPeersalways rebuildspeersfromclients(matching
GetXrayConfigfield for field) and drops theclientskey.Summary
WireGuard inbounds hosted on a sub-node now keep working after a client is added
from the master. Previously, adding a WireGuard client on the master dropped every
WireGuard connection on the sub-node (across all clients of the inbound) until Xray
was manually restarted on the node. Adding the same client directly on the node worked.
Why
The panel stores WireGuard clients under
settings.clients(the shape every other protocol uses), but xray-core's wireguard inbound is configured withsettings.peers. Theclients→peersconversion lived only in the full-config path (XrayService.GetXrayConfig), which runs on a full Xray restart. The live gRPCAddInboundpath goes through(*Inbound).GenXrayInboundConfig, which passed the WireGuard settings verbatim — withclientsand nopeers.Adding a client on the master does two things: it pushes the client to the node (a safe single-peer hot-add via
AlterInbound{AddUser}, which succeeds) and it marks the node dirty. The reconcile then pushespanel/api/inbounds/update/:idto the node, whoseInboundService.UpdateInbound(the inbound is local there,NodeID == nil) applies it live viaDelInbound+AddInbound(buildRuntimeInboundForAPI→Local.AddInbound→GenXrayInboundConfig). That re-adds the wireguard inbound with zero peers, wiping the device and dropping every connected client — hence "only a restart fixes it".Adding the same client directly on the node worked, because that path only does the safe single-peer hot-add (the inbound is not marked dirty, so no reconcile and no peerless rebuild). The same peerless rebuild also affected plain WireGuard inbound edits on a standalone panel.
Type of change
Areas affected
How was this tested?
New unit tests in
internal/database/model, mirroring the existing settings-transform helper tests (StripVlessInboundEncryption,HealShadowsocksClientMethods):TestWireguardClientsToPeers— asserts the conversion dropsclients, emitspeerswith the correct fields (publicKey,allowedIPs,preSharedKey,keepAlive), preservessecretKey, and skips disabled clients.TestWireguardClientsToPeersIdempotent— asserts the no-op paths (peers already present / clients absent), so the full-config path that already populated peers is unaffected.TestGenXrayInboundConfigWireguardConvertsPeers— end-to-end throughGenXrayInboundConfig; verified red without the fix (clientspersisted,peerswasnil).The emitted peer shape was verified field-for-field against the
peersmap built byGetXrayConfig.Full local gate passed:
make verify(gen-check, lint, typecheck, test, build) — OKgolangci-lint run ./internal/database/model/— 0 issuesManual testing — two-panel master/sub-node with a real WireGuard client:
docker compose: a master and a sub-node on one bridge network (eachcontainer in its own netns, so no Xray API / sub-port collisions), plus a third
container as a pure WireGuard client (
wireguard-tools,/dev/net/tun).hosted on the node, and added client A from the master.
node's live device had zero peers (
0 B received). A client added directly on thenode worked, but re-adding any client from the master then dropped it to 100%
packet loss until Xray was restarted on the node — exactly the reported bug.
confirmed handshake, ping to the tunnel address
10.0.0.1, and egress(
curlrouted through the node). Then added a second client Bfrom the master to trigger the node reconcile while pinging continuously: the tunnel
showed only a brief blip during the
DelInbound+AddInbounddevice rebuild(~15 dropped packets) and recovered on its own — existing peers preserved. On the
unfixed build the same step dropped the tunnel permanently.
Screenshots / recordings
N/A — no UI changes.
Breaking changes
None.
Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.