mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #7088] fix(clients): re-add WireGuard peers with their keys instead of restarting Xray #6640
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#6640
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/7088
Author: @Dv2Corn
Created: 11/6/2026
Status: 🔄 Open
Base:
main← Head:fix/wireguard-readd-keys📝 Commits (5)
7e61c74fix(traffic): re-add a quota-disabled WireGuard client on reset without restarting Xraycbb530bfix(traffic): keep Xray running when auto-renew re-adds a WireGuard peer with keepAlive3f27a77fix(clients): re-add WireGuard peers with their keys on bulk enable44d1b9efix(inbounds): validate client emails and subIds on inbound create8837a4afix(clients): push sidecar config after bulk enable flips the traffic rows📊 Changes
7 files changed (+379 additions, -61 deletions)
View changed files
📝
internal/web/service/client_bulk.go(+28 -13)📝
internal/web/service/client_crud.go(+12 -0)📝
internal/web/service/client_inbound_apply.go(+2 -28)➕
internal/web/service/client_reset_core_readd_test.go(+262 -0)📝
internal/web/service/inbound.go(+6 -0)➕
internal/web/service/inbound_add_client_email_test.go(+42 -0)📝
internal/web/service/inbound_traffic.go(+27 -20)📄 Description
Summary
Three paths re-add a client to the running core with an account map the core's WireGuard builder refuses. Each failed add falls back to a full Xray restart, which drops every connected user on the panel. This PR builds that map in one place, so the keys always go with it, and fixes a related gap where
/inbounds/addand/inbounds/importstore client emails and subIds that the client API refuses.Why
All three restarts happen on a plain WireGuard inbound with default settings:
resetClientTrafficLockedbuilds the map by hand withoutpublicKey,allowedIPs,preSharedKeyorkeepAlive(inbound_traffic.go#L766-L775).AddUserfails withmissing required user field "publicKey"(xray/api.go#L915), and the reset setsneedRestart(inbound_traffic.go#L841-L843). The same call is also made for AmneziaWG, MTProto and TUIC inbounds, whereAddUserchanges nothing, so the re-enabled peer never reaches the running device.apiUserFromClient(inbound_traffic.go#L369). In that JSONkeepAliveis a number, but the builder only accepts a string (xray/api.go#L938):invalid type for user field "keepAlive": float64. Every renewal of such a peer restarts Xray.bulkSetEnableInboundClientsbuilds its own map without the WireGuard keys (client_bulk.go#L1813-L1822), with the same result as (1). On AmneziaWG, MTProto and TUIC inbounds the bulk toggle has the same no-op problem as (1).The single-client add and update paths already send the full map (client_inbound_apply.go#L694-L707, #L1157-L1170). The three paths above had simply fallen behind.
Separately,
AddInbound(inbound.go#L1297) creates client records from the inbound's settings without runningvalidateClientEmail/validateClientSubID(client_crud.go#L39-L54). As a result/panel/api/inbounds/addand/inbounds/importstill accept the names.and..that #7062 rejects on the client API, as well as emails and subIds containing/or whitespace. A subscription URL for such a subId can never be reached.What changes:
coreUserFromClientbuilds the account map, includingpublicKey,allowedIPs,preSharedKeyandkeepAlive. The reset, bulk enable and single-client add/update paths all use it.applyTrafficMutationBatch, and bulk enable/disable callsapplyLocalMtproto/applyLocalAmneziaWG/applyLocalTuic. Both already route the sidecar protocols to their reconcilers elsewhere, and the single-client update path does the same.client_trafficsrows are switched.buildInboundForLocalRuntimeleaves out every client whose traffic row is off, so a push from the per-inbound fan-out, beforeBulkSetEnableflips those rows, still left a bulk-enabled client off the device until the 10-second reconcile job. The fan-out now only records the sidecar protocol, andBulkSetEnablepushes each such inbound underlockInboundafter the traffic-row transaction.apiUserFromClientconverts a numerickeepAliveto the string the builder takes.AddInboundvalidates every client's email and subId with the client API's rules. A push from the master (FromNodeSync) is exempt: the node takes what its master already holds, and refusing a legacy name there would only leave the node out of sync.Type of change
Areas affected
How was this tested?
The new tests go through the real
xray.XrayAPI.AddUseraccount builder, using a stub HandlerService that accepts every call. AmneziaWG/MTProto/TUIC behave like the local runtime, where onlyUpdateInboundreaches the device.internal/web/service/client_reset_core_readd_test.goTestResetTrafficOfQuotaDisabledWireGuardPeerNeedsNoRestart: onmainit fails withmissing required user field "publicKey", and passes with the fix.TestResetTrafficOfQuotaDisabledAmneziaWGPeerReachesTheDevice: onmainno inbound reconcile is pushed; with the fix it passes.TestAutoRenewOfWireGuardPeerWithKeepAliveNeedsNoRestart: onmainit fails withinvalid type for user field "keepAlive": float64, and passes with the fix.TestBulkEnableOfWireGuardPeerNeedsNoRestart: onmainit fails withmissing required user field "publicKey", and passes with the fix.TestBulkSetEnableOfSidecarClientReachesTheDevice: AmneziaWG, MTProto and TUIC subtests. Each switches an enabled client off in bulk and back on, so the enable starts from the state bulk disable leaves (traffic row off), and checks that both reach the device. Onmainnothing is pushed. With the push still in the per-inbound fan-out, all three fail withbulk enable=true never reached the <protocol> sidecar; pushed 1 updates; with the push after the traffic rows, all three pass.internal/web/service/inbound_add_client_email_test.goTestAddInboundRefusesClientNamesTheClientAPIRefusescovers.,..,a/band the subIdsub one. Onmainall four are accepted; with the fix all four are refused.TestAddInboundFromMasterPushKeepsALegacyDotName: a master push with.is still stored. It passes both before and after.Run with Go 1.27.3 and the
internal/web/diststub the CI uses:go build ./...,go vet ./...andgofmt -lare clean.go test -shuffle=on -count=1 ./...passes, apart fromTestResetTrafficByEmail_ReenablesEveryInboundOfTheClient(from #6987). That test is flaky onmaintoo: it failed 11 of 200 runs onmainand 19 of 200 on this branch. It runs the two inbound resets side by side without the serial traffic writer the panel uses. The second reset can then read the record as still off after the first one has zeroed the counters, and it keeps the client off as if it had been disabled by hand. This PR does not touch it; starting the traffic writer in that test (resetTrafficWriterForTest(t)+StartTrafficWriter()) makes it stable.go test -race -count=1 ./internal/web/service ./internal/web/controllerpasses.go test -shuffle=on -count=1 ./internal/web/serviceandgo test -race -count=1 ./internal/web/servicepass;go vetandgofmt -lon the package are clean.Screenshots / recordings
N/A
Breaking changes
None for clients the panel already accepts.
/inbounds/addand/inbounds/importnow refuse an inbound whose settings contain a client email or subId that/clients/addwould refuse.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.