Merge pull request #11909 from vishjain/user/vishal/memory-leak/master

Cleanup on ticker allocations.
pull/12975/head
Medya Ghazizadeh 2021-11-17 13:23:54 -06:00 committed by GitHub
commit 48424c5393
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 3 deletions

View File

@ -48,21 +48,38 @@ func main() {
// TODO: #10595 make this configurable
const interval = time.Minute * 1
// Check if interval is greater than 0 so NewTicker does not panic.
if interval <= 0 {
exit.Message(reason.Usage, "Auto-pause interval must be greater than 0,"+
" not current value of {{.interval}}", out.V{"interval": interval.String()})
}
tickerChannel := time.NewTicker(interval)
// Check current state
alreadyPaused()
// channel for incoming messages
go func() {
for {
// On each iteration new timer is created
select {
// TODO: #10596 make it memory-leak proof
case <-time.After(interval):
case <-tickerChannel.C:
runPause()
case <-unpauseRequests:
fmt.Printf("Got request\n")
if runtimePaused {
runUnpause()
// Reset once cluster has been unpaused.
tickerChannel.Reset(interval)
// Avoid race where tick happens before Reset call and after unPause.
for {
select {
case <-tickerChannel.C:
default:
break
}
}
}
done <- struct{}{}