Skip to content

Commit

Permalink
Fix: Panic when path limit exceeded (main)
Browse files Browse the repository at this point in the history
The stats module now panics when the path limit is
exceeded instead of using an overflow bucket. This
change improves error handling and provides more
actionable feedback to the user.  It also simplifies
the code by removing the overflow logic.  If you
encounter this panic, please open an issue on GitHub
or raise the `stats.maxPaths` constant.
  • Loading branch information
JasonLovesDoggo committed Mar 2, 2025
1 parent 5905b71 commit 78fdb9b
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions utils/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"context"
"fmt"
"log"
"sync"
"sync/atomic"
Expand All @@ -12,8 +13,8 @@ import (
)

const (
// How many paths to track before using overflow
maxPaths = 120
// How many paths to track before panicking
maxPaths = 45
// Threshold for total count to trigger save
saveThreshold = 100
)
Expand Down Expand Up @@ -57,14 +58,16 @@ func (sm *StatManager) RecordStat(path string, count int64) {
if !loaded {
// Check if we've hit the path limit
if sm.pathCount.Load() >= maxPaths {
// Use overflow bucket
val, _ = sm.stats.LoadOrStore("overflow", new(int64))
} else {
// Create new counter
val = new(int64)
sm.stats.Store(path, val)
sm.pathCount.Add(1)
// Panic instead of using overflow bucket
panic(fmt.Sprintf("Stats path limit exceeded: %d paths is the maximum allowed... if you see this, "+
"please make a issue @ https://github.com/JasonLovesDoggo/abacus or raise stats.maxPaths",
maxPaths))
}

// Create new counter
val = new(int64)
sm.stats.Store(path, val)
sm.pathCount.Add(1)
}

// Update path counter atomically
Expand Down

0 comments on commit 78fdb9b

Please sign in to comment.