Skip to content
[mirror] Go supplementary time packages
Go
Branch: master
Clone or download
lzhfromustc and Sajmani Add critical section to protect lim.limit
***Description***
Among 9 usages of lim.limit , 8 of them are protected by `lim.mu.Lock()`, but the one at line 226 is not protected. So I add a critical section to protect the read operation.

Among 8 usages of lim.limit that are protected, there are 2 usages at line 350 and 357 in function `lim.advance()`. They may seem to be unprotected at first glance, since `lim.mu.Lock()` doesn't appear in `lim.advance()`, but actually all three usages of `lim.advance()` are in critical section.

***How to trigger this bug***
I found this bug occasionally by my static checker, so I can only come up with a hypothesis to trigger it:

If one goroutine is calling `rate.WaitN()` and another goroutine is calling `rate.SetLimitAt()`, then the read operation in `rate.WaitN()` and the write operation in `rate.SetLimitAt()` will race.

***About my patch***
There are several ways to fix this bug, and I chose an efficient but not elegant one. Please let me know if you think other ways are better.

Change-Id: I229bc06a2caa483b9dfb0f4e682cfc144c5aa07c
GitHub-Last-Rev: 192792c
GitHub-Pull-Request: #7
Reviewed-on: https://go-review.googlesource.com/c/time/+/188898
Reviewed-by: Sameer Ajmani <sameer@golang.org>
Latest commit 555d28b Oct 24, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
rate Add critical section to protect lim.limit Oct 24, 2019
AUTHORS initial commit Nov 3, 2015
CONTRIBUTING.md CONTRIBUTING.md: remove note about not accepting Pull Requests Mar 14, 2018
CONTRIBUTORS initial commit Nov 3, 2015
LICENSE initial commit Nov 3, 2015
PATENTS initial commit Nov 3, 2015
README.md README: add better links, Markdown Sep 27, 2017
go.mod all: add a go.mod file Mar 8, 2019

README.md

Go Time

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.

You can’t perform that action at this time.