limit: clamp bandwidth limiter burst (#5471)

This commit is contained in:
fatedier
2026-08-09 17:30:39 +08:00
committed by GitHub
parent 5b68148f11
commit f666d97b64
6 changed files with 117 additions and 2 deletions
+6
View File
@@ -35,6 +35,12 @@ func NewReader(r io.Reader, limiter *rate.Limiter) *Reader {
func (r *Reader) Read(p []byte) (n int, err error) {
b := r.limiter.Burst()
if b <= 0 {
if len(p) == 0 {
return 0, nil
}
return 0, invalidBurstError(b)
}
if b < len(p) {
p = p[:b]
}