diff --git a/internal/web/controller/client-wireguard-devices.go b/internal/web/controller/client-wireguard-devices.go index b350d5550..b6abf3d36 100644 --- a/internal/web/controller/client-wireguard-devices.go +++ b/internal/web/controller/client-wireguard-devices.go @@ -3,7 +3,6 @@ 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" ) @@ -17,12 +16,9 @@ func (a *ClientController) finishWireguardDeviceWrite(c *gin.Context, err error) jsonObj(c, nil, err) return } - // 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() - } + // Not left to the 30 s reconcile tick: until then a disabled or deleted device + // kept its tunnel (measured 12-24 s on a running panel). + a.xrayService.ReconcileNow() notifyClientsChanged() a.wireguardDevices(c) } diff --git a/internal/web/service/inbound.go b/internal/web/service/inbound.go index 159fe8881..f8bb2496f 100644 --- a/internal/web/service/inbound.go +++ b/internal/web/service/inbound.go @@ -2433,8 +2433,9 @@ func applyInboundUserOps(rt runtime.Runtime, running, next *model.Inbound) bool } if next.Protocol == model.WireGuard { if !diff.Empty() { - // Reconcile peers and the Xray config snapshot together. - (&XrayService{}).SetToNeedReconcile() + // Peers and the config snapshot move together, and now: a peer removed on a + // node kept its tunnel until the node's next reconcile tick. + (&XrayService{}).ReconcileNow() } return true } diff --git a/internal/web/service/xray.go b/internal/web/service/xray.go index 7327679e3..130272eac 100644 --- a/internal/web/service/xray.go +++ b/internal/web/service/xray.go @@ -1842,6 +1842,15 @@ func (s *XrayService) SetToNeedRestart() { // SetToNeedReconcile schedules config reconciliation without forcing an unchanged core to restart. func (s *XrayService) SetToNeedReconcile() { isNeedXrayReconcile.Store(true) } +// ReconcileNow applies a change at once instead of at the 30 s tick. A core that is +// down only stays flagged: starting it is the tick's job. +func (s *XrayService) ReconcileNow() { + s.SetToNeedReconcile() + if s.IsXrayRunning() { + s.ApplyPendingRestart() + } +} + // GetXrayAPIPort returns the port the local xray process is listening on // for its gRPC HandlerService, or 0 when xray isn't currently running. // Exposed for the runtime package's LocalRuntime adapter without a