aboutsummaryrefslogtreecommitdiff
path: root/hotline/server.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2026-05-28 16:22:24 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2026-05-28 16:22:24 -0700
commitb772019454ebb804c313e717ae98eb68430e780e (patch)
treea12ffc1e5de4d7e1612edaea03174043a6c55784 /hotline/server.go
parent2f46f87177234070044b5304ca3e0db471699ad8 (diff)
Refactor Stats to typed keys and fix peak-tracking race
Replace the map-backed Stats counter with a fixed [numStats]int array indexed by a new StatKey enum, eliminating the hand-maintained map initialization and the parallel string-keyed Values() map. Fix a check-then-act race in the connection peak tracking: the old Get-then-Set across two lock acquisitions could let concurrent connections clobber each other's update. The new atomic Max method does the compare-and-set under a single lock. Values() now returns a typed StatValues struct whose JSON tags preserve the existing /api/v1/stats wire format.
Diffstat (limited to 'hotline/server.go')
-rw-r--r--hotline/server.go6
1 files changed, 2 insertions, 4 deletions
diff --git a/hotline/server.go b/hotline/server.go
index dcb90e7..d757062 100644
--- a/hotline/server.go
+++ b/hotline/server.go
@@ -157,7 +157,7 @@ func NewServer(options ...Option) (*Server, error) {
return &server, nil
}
-func (s *Server) CurrentStats() map[string]interface{} {
+func (s *Server) CurrentStats() StatValues {
return s.Stats.Values()
}
@@ -648,9 +648,7 @@ func (s *Server) handleNewConnection(ctx context.Context, rwc io.ReadWriteCloser
c.Server.Stats.Increment(StatConnectionCounter, StatCurrentlyConnected)
defer c.Server.Stats.Decrement(StatCurrentlyConnected)
- if len(s.ClientMgr.List()) > c.Server.Stats.Get(StatConnectionPeak) {
- c.Server.Stats.Set(StatConnectionPeak, len(s.ClientMgr.List()))
- }
+ c.Server.Stats.Max(StatConnectionPeak, len(s.ClientMgr.List()))
// Scan for new transactions and handle them as they come in.
for scanner.Scan() {