x/time/rate: correctly handle 0 limits

Decrementing the burst in the reserveN method will frequently lead to us
setting the burst to 0 which makes the limiter mostly unusable.

This code was originally added in https://go.dev/cl/323429 to fix #39984
but the implementation introduced a different bug. To avoid regressing
to the behaviour described in #39984, pre-fill the limiter to the burst
value in the constructor.

Fixes #68541

Change-Id: Iab3b85d548a44fcb2d058336e5bbf11b19ea67b1
Reviewed-on: https://go-review.googlesource.com/c/time/+/600876
Reviewed-by: Sameer Ajmani <sameer@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Sameer Ajmani <sameer@golang.org>
2 files changed
tree: 09383df1d682f0319dea65727baa8a1577e451a5
  1. rate/
  2. CONTRIBUTING.md
  3. go.mod
  4. LICENSE
  5. PATENTS
  6. README.md
README.md

Go Time

Go Reference

This repository provides supplementary Go time packages.

Download/Install

The easiest way to install is to run go get -u golang.org/x/time. You can also manually git clone the repository to $GOPATH/src/golang.org/x/time.

Report Issues / Send Patches

This repository uses Gerrit for code changes. To learn how to submit changes to this repository, see https://golang.org/doc/contribute.html.

The main issue tracker for the time repository is located at https://github.com/golang/go/issues. Prefix your issue with “x/time:” in the subject line, so it is easy to find.