fix(traffic): re-enable clients and serialize the write in Reset All Client Traffic

ClientService.ResetAllTraffics zeroed up/down but, unlike every sibling reset
path, never restored enable=true, so clients that had been auto-disabled for
exceeding their quota stayed cut with zero usage after a reset. It also wrote
client_traffics directly on the shared DB handle instead of through the serial
traffic writer, reintroducing the cross-transaction lock-order deadlock the
writer exists to prevent. Restore enable and run the reset inside
submitTrafficWrite within one transaction.
This commit is contained in:
MHSanaei
2026-07-15 02:08:06 +02:00
parent b6928f4939
commit 3eb214d022
2 changed files with 39 additions and 9 deletions
+15 -9
View File
@@ -200,15 +200,21 @@ func (s *ClientService) resetAllClientTrafficsLocked(id int) error {
}
func (s *ClientService) ResetAllTraffics() (bool, error) {
db := database.GetDB()
res := db.Model(&xray.ClientTraffic{}).
Where("1 = 1").
Updates(map[string]any{"up": 0, "down": 0})
if res.Error != nil {
return false, res.Error
}
if err := db.Where("1 = 1").Delete(&model.ClientGlobalTraffic{}).Error; err != nil {
var affected int64
err := submitTrafficWrite(func() error {
return database.GetDB().Transaction(func(tx *gorm.DB) error {
res := tx.Model(&xray.ClientTraffic{}).
Where("1 = 1").
Updates(map[string]any{"enable": true, "up": 0, "down": 0})
if res.Error != nil {
return res.Error
}
affected = res.RowsAffected
return tx.Where("1 = 1").Delete(&model.ClientGlobalTraffic{}).Error
})
})
if err != nil {
return false, err
}
return res.RowsAffected > 0, nil
return affected > 0, nil
}