Merge pull request #10102 from catap/prevent-zero-timer-1.7

[release/1.7] Prevent GC from schedule itself with 0 period.
This commit is contained in:
Kazuyoshi Kato authored and GitHub committed 2024-04-22 10:02:39 -07:00
commit 6a99fcc88c
1 file changed
+6
+6
View File
@@ -246,6 +246,7 @@ func schedule(d time.Duration) (<-chan time.Time, *time.Time) {
}
func (s *gcScheduler) run(ctx context.Context) {
const minimumGCTime = float64(5 * time.Millisecond)
var (
schedC <-chan time.Time
@@ -343,6 +344,11 @@ func (s *gcScheduler) run(ctx context.Context) {
// runtime in between gc to reach the pause threshold.
// Pause threshold is always 0.0 < threshold <= 0.5
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)
}