We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2dfbcb8 commit 71dcfd7Copy full SHA for 71dcfd7
sleep/handler.go
@@ -52,7 +52,18 @@ func Handle(w http.ResponseWriter, r *http.Request) {
52
minMs := minSleep.Milliseconds()
53
maxMs := maxSleep.Milliseconds()
54
55
- randMs := random.Int63n(maxMs-minMs) + minMs
+ // Normalize and handle edge cases to avoid panic in Int63n
56
+ if maxMs < minMs {
57
+ minMs, maxMs = maxMs, minMs
58
+ }
59
+
60
+ var randMs int64
61
+ rangeMs := maxMs - minMs
62
+ if rangeMs <= 0 {
63
+ randMs = minMs // min == max, use fixed duration
64
+ } else {
65
+ randMs = random.Int63n(rangeMs+1) + minMs // inclusive of max
66
67
68
sleepDuration, _ := time.ParseDuration(fmt.Sprintf("%dms", randMs))
69
0 commit comments