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).
This commit is contained in:
Sanaei
2026-11-24 23:52:09 +03:30
parent eccf2e71bd
commit c1cf280055
@@ -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)
}