fix(traffic): commit a traffic tick even when a best-effort maintenance helper fails

addTrafficLocked stages the inbound and client deltas, then runs three helpers
(auto-renew, disable depleted clients, disable depleted inbounds) that are meant
to log and continue. All three reused the function-scope err that the deferred
commit/rollback inspects, so the last helper's error decided the whole tick: a
failure in disableInvalidInbounds rolled back the already-staged traffic while
AddTraffic reported success, and because xray had already advanced its counter
baseline that traffic was lost for good. Give each best-effort helper its own
error variable so only a genuine staging failure rolls the tick back.
This commit is contained in:
MHSanaei
2026-07-15 02:04:48 +02:00
parent f7cae8d1cf
commit b6928f4939
2 changed files with 63 additions and 9 deletions
+9 -9
View File
@@ -51,25 +51,25 @@ func (s *InboundService) addTrafficLocked(inboundTraffics []*xray.Traffic, clien
return false, false, err
}
needRestart0, count, err := s.autoRenewClients(tx)
if err != nil {
logger.Warning("Error in renew clients:", err)
needRestart0, count, renewErr := s.autoRenewClients(tx)
if renewErr != nil {
logger.Warning("Error in renew clients:", renewErr)
} else if count > 0 {
logger.Debugf("%v clients renewed", count)
}
disabledClientsCount := int64(0)
needRestart1, count, err := s.disableInvalidClients(tx)
if err != nil {
logger.Warning("Error in disabling invalid clients:", err)
needRestart1, count, disableClientsErr := s.disableInvalidClients(tx)
if disableClientsErr != nil {
logger.Warning("Error in disabling invalid clients:", disableClientsErr)
} else if count > 0 {
logger.Debugf("%v clients disabled", count)
disabledClientsCount = count
}
needRestart2, count, err := s.disableInvalidInbounds(tx)
if err != nil {
logger.Warning("Error in disabling invalid inbounds:", err)
needRestart2, count, disableInboundsErr := s.disableInvalidInbounds(tx)
if disableInboundsErr != nil {
logger.Warning("Error in disabling invalid inbounds:", disableInboundsErr)
} else if count > 0 {
logger.Debugf("%v inbounds disabled", count)
}