Merge pull request #9795 from catap/prevent-zero-timer

Prevent GC from schedule itself with 0 period.
This commit is contained in:
Maksym Pavlenko 2024-02-21 21:15:00 +00:00 committed by GitHub
commit 67ff3dbc8d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -234,6 +234,7 @@ func schedule(d time.Duration) (<-chan time.Time, *time.Time) {
} }
func (s *gcScheduler) run(ctx context.Context) { func (s *gcScheduler) run(ctx context.Context) {
const minimumGCTime = float64(5 * time.Millisecond)
var ( var (
schedC <-chan time.Time schedC <-chan time.Time
@ -331,6 +332,11 @@ func (s *gcScheduler) run(ctx context.Context) {
// runtime in between gc to reach the pause threshold. // runtime in between gc to reach the pause threshold.
// Pause threshold is always 0.0 < threshold <= 0.5 // Pause threshold is always 0.0 < threshold <= 0.5
avg := float64(gcTimeSum) / float64(collections) avg := float64(gcTimeSum) / float64(collections)
// Enforce that avg is no less than minimumGCTime
// to prevent immediate rescheduling
if avg < minimumGCTime {
avg = minimumGCTime
}
interval = time.Duration(avg/s.pauseThreshold - avg) interval = time.Duration(avg/s.pauseThreshold - avg)
} }