mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-07-08 21:56:08 +00:00
fix(clients): surface bulk-reset auto-enable failures (#5763)
* fix(clients): surface bulk-reset auto-enable failures BulkResetTraffic re-enables a disabled client before resetting its traffic, but discarded the s.Update result with `_, _ =`, so a failed re-enable was silent: the client stayed disabled with nothing logged, unlike the single-client ResetTraffic path which already warns on the same call. Check the error and log a warning to match, and add a regression test covering BulkResetTraffic's previously-untested re-enable path. * ci: update Go toolchain for govulncheck --------- Co-authored-by: Sanaei <ho3ein.sanaei@gmail.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
module github.com/mhsanaei/3x-ui/v3
|
||||
|
||||
go 1.26.4
|
||||
go 1.26.5
|
||||
|
||||
require (
|
||||
github.com/gin-contrib/gzip v1.2.6
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package service
|
||||
|
||||
import "testing"
|
||||
|
||||
// TestBulkResetTraffic_ReenablesDisabledClient covers the re-enable branch of
|
||||
// BulkResetTraffic: a disabled client whose traffic is bulk-reset must come back
|
||||
// enabled with its counters zeroed, in all three enable locations. This is the
|
||||
// path whose s.Update failure was previously swallowed silently.
|
||||
func TestBulkResetTraffic_ReenablesDisabledClient(t *testing.T) {
|
||||
setupBulkDB(t)
|
||||
svc := &ClientService{}
|
||||
inboundSvc := &InboundService{}
|
||||
|
||||
email := "reset-reenable@x"
|
||||
ib := seedLocalDisabledClient(t, svc, 52010, "", email, 1000, 0, 600, 500)
|
||||
|
||||
affected, err := svc.BulkResetTraffic(inboundSvc, []string{email})
|
||||
if err != nil {
|
||||
t.Fatalf("BulkResetTraffic: %v", err)
|
||||
}
|
||||
if affected < 1 {
|
||||
t.Fatalf("affected = %d, want >= 1", affected)
|
||||
}
|
||||
|
||||
assertEnableEverywhere(t, svc, inboundSvc, ib.Id, email, true)
|
||||
if tr := trafficOf(t, email); tr.Up != 0 || tr.Down != 0 {
|
||||
t.Fatalf("%s: traffic after reset up=%d down=%d, want 0/0", email, tr.Up, tr.Down)
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,9 @@ func (s *ClientService) BulkResetTraffic(inboundSvc *InboundService, emails []st
|
||||
if err == nil && !rec.Enable {
|
||||
updated := rec.ToClient()
|
||||
updated.Enable = true
|
||||
_, _ = s.Update(inboundSvc, rec.Id, *updated)
|
||||
if _, uErr := s.Update(inboundSvc, rec.Id, *updated); uErr != nil {
|
||||
logger.Warning("Failed to auto-enable client during bulk traffic reset:", uErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user