fix(clients): restore depleted clients on renewal and prioritize operator writes (#6987)

Restore usable clients when renewed, avoid duplicate reset updates, and prioritize operator writes in the serialized traffic writer. Preserve manual disables and keep every inbound consistent after traffic resets.
This commit is contained in:
Mahdi Fallahnejhad
2026-11-05 20:37:52 +03:30
committed by GitHub
parent e4935be861
commit dbb6212988
13 changed files with 684 additions and 92 deletions
+15
View File
@@ -782,6 +782,12 @@ func (s *ClientService) update(inboundSvc *InboundService, id int, updated model
updated.Secret = existing.Secret
}
// A client the quota loop switched off comes back on when this update
// restores a usable window, as BulkAdjust already does on a renewal (#5619).
if !updated.Enable && s.renewalReenables(existing.Email, updated.TotalGB, updated.ExpiryTime) {
updated.Enable = true
}
if updated.Email != existing.Email {
var collisionCount int64
if err := database.GetDB().Model(&model.ClientRecord{}).
@@ -936,6 +942,15 @@ func (s *ClientService) update(inboundSvc *InboundService, id int, updated model
}).Error; err != nil {
return needRestart, err
}
// No inbound left, so UpdateClientStat never runs; re-assert the
// enforcement row's off switch here or a re-enabled client stays off.
if merged.Enable {
if err := database.GetDB().Model(xray.ClientTraffic{}).
Where("email = ?", existing.Email).
UpdateColumn("enable", true).Error; err != nil {
return needRestart, err
}
}
}
reverseStr := ""