Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Func Wait in package ratelimit could got blocked if time moves backwards for any reason #22

Open
lichuqiang opened this issue Nov 17, 2017 · 1 comment

Comments

@lichuqiang
Copy link

lichuqiang commented Nov 17, 2017

We import package ratelimit in Kubernetes and met a scenario, not sure whether the issue should be filed here.
The scenario is that when time happened moves backwards for any reason, func take that calculate the time to sleep would get a huge number here:

	endTick := currentTick + (-avail+tb.quantum-1)/tb.quantum
	endTime := tb.startTime.Add(time.Duration(endTick) * tb.fillInterval)
	waitTime := endTime.Sub(now)
	if waitTime > maxWait {
		return 0, false
	}

An available way for the issue might be adding a protection before calculating waitTime, say a comparision between now and startTime.

/cc @thockin

@rogpeppe
Copy link
Contributor

The scenario is that when time happened moves backwards for any reason, func take that calculate the time to sleep would get a huge number here:

Given that time.Duration is signed, won't that happen only if the time moves back more than ~290 years?
I guess that it's possible that might happen in endTime is the zero time. Is that what happened?

Checking for overflow seems like a reasonable plan anyway though - PRs happily accepted. It would be good if it didn't slow things down much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants