fix: remove duplicate user_manager instance and reset traffic counters after report
Some checks failed
Build / Calculate version (push) Has been cancelled
Build / Build binary (push) Has been cancelled
Build / Build Darwin binaries (push) Has been cancelled
Build / Build Windows binaries (push) Has been cancelled
Build / Build Android (push) Has been cancelled
Build / Publish Android (push) Has been cancelled
Build / Build Apple clients (push) Has been cancelled
Build / Upload builds (push) Has been cancelled

- Remove second user_manager creation via serviceManager.Create to prevent
  double-counting (both instances tracked the same connections)
- Reset per-user atomic counters after each successful traffic report so
  the control panel receives independent per-interval deltas instead of
  unbounded cumulative values
This commit is contained in:
Niko Marmeladkov 2026-06-23 12:24:56 +03:00
parent 691cce1361
commit 14bacec75a
Signed by untrusted user who does not match committer: Niko
GPG key ID: E3B955F9442D44E3
2 changed files with 14 additions and 12 deletions

12
box.go
View file

@ -441,18 +441,6 @@ func New(options Options) (*Box, error) {
service.MustRegister[adapter.V2RayServer](ctx, v2rayServer)
}
}
if experimentalOptions.UserManager != nil {
err = serviceManager.Create(
ctx,
logFactory.NewLogger("service/user_manager"),
"user_manager",
C.TypeUserManager,
experimentalOptions.UserManager,
)
if err != nil {
return nil, E.Cause(err, "create user_manager")
}
}
if ntpOptions.Enabled {
ntpDialer, err := dialer.New(ctx, ntpOptions.DialerOptions, ntpOptions.ServerIsDomain())
if err != nil {

View file

@ -576,6 +576,20 @@ func (m *Manager) reportTrafficToServer() {
}
resp.Body.Close()
m.logger.Debug("traffic reported, users=", len(traffic))
// Reset counters after successful report so the next report only
// contains fresh traffic (delta since last report).
// This avoids overcounting when multiple nodes or user_manager
// instances report for the same user — the control panel always
// receives independent per-interval values.
m.trafficAccess.Lock()
for username := range traffic {
if stored, ok := m.traffic[username]; ok {
stored.Tx.Add(-traffic[username].Tx)
stored.Rx.Add(-traffic[username].Rx)
}
}
m.trafficAccess.Unlock()
}
// HTTP API