mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-25 12:04:44 +03:00
fix(wireguard): apply a peer change pushed to a node at once
The previous commit applied a device write at once, but only on the panel that received the request. A node takes the same change as an inbound update from its master, and that path still flagged the 30 s reconcile: a device disabled on the master kept its tunnel on the node until the node's next tick. ReconcileNow is the one place both paths go through. It applies when the core runs and only flags when it is down, so a device write never starts a core the tick has not started. Measured with a real master and node panel (Xray 26.11.9, kernel WireGuard clients): a device disabled on the master is cut on the node after 5 s instead of 11-30 s, and a new one connects 7 s after it is added. No unit test reaches it, a test process is never running; the scenario is the proof.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user