From c1cf280055246581a33bb5be7e40b8e4eff63bd7 Mon Sep 17 00:00:00 2001 From: Sanaei Date: Tue, 24 Nov 2026 23:52:09 +0330 Subject: [PATCH] fix(wireguard): apply a device change at once A device write only flagged the next reconcile, which runs every 30 s. Until then a disabled or deleted device kept its tunnel, and a new one could not connect: 12-24 s measured on a running panel, under 1 s now. The handler applies the change through the same non-forced path the reconcile uses, and falls back to the flag when that fails. No unit test reaches it: the controller tests run without a core. The Docker timeline shows it (toggle a device, read `wg show` on the client and the peer list of the core). --- internal/web/controller/client-wireguard-devices.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/web/controller/client-wireguard-devices.go b/internal/web/controller/client-wireguard-devices.go index 71cba07be..b350d5550 100644 --- a/internal/web/controller/client-wireguard-devices.go +++ b/internal/web/controller/client-wireguard-devices.go @@ -3,6 +3,7 @@ package controller import ( "github.com/gin-gonic/gin" + "github.com/mhsanaei/3x-ui/v3/internal/logger" "github.com/mhsanaei/3x-ui/v3/internal/web/service" ) @@ -16,7 +17,12 @@ func (a *ClientController) finishWireguardDeviceWrite(c *gin.Context, err error) jsonObj(c, nil, err) return } - a.xrayService.SetToNeedReconcile() + // Applied now, not at the next 30 s reconcile tick: until then a disabled or + // deleted device kept its tunnel (measured 12-24 s on a running panel). + if applyErr := a.xrayService.RestartXray(false); applyErr != nil { + logger.Warning("apply WireGuard device change failed, left to the next reconcile:", applyErr) + a.xrayService.SetToNeedReconcile() + } notifyClientsChanged() a.wireguardDevices(c) }