File tree 3 files changed +35
-6
lines changed 3 files changed +35
-6
lines changed Original file line number Diff line number Diff line change @@ -653,7 +653,7 @@ type p struct {
653
653
// timerModifiedEarlier status. Because the timer may have been
654
654
// modified again, there need not be any timer with this value.
655
655
// This is updated using atomic functions.
656
- // This is 0 if the value is unknown .
656
+ // This is 0 if there are no timerModifiedEarlier timers .
657
657
timerModifiedEarliest uint64
658
658
659
659
// Per-P GC state
Original file line number Diff line number Diff line change @@ -668,11 +668,6 @@ func adjusttimers(pp *p, now int64) {
668
668
if verifyTimers {
669
669
verifyTimerHeap (pp )
670
670
}
671
- // There are no timers to adjust, so it is safe to clear
672
- // timerModifiedEarliest. Do so in case it is stale.
673
- // Everything will work if we don't do this,
674
- // but clearing here may save future calls to adjusttimers.
675
- atomic .Store64 (& pp .timerModifiedEarliest , 0 )
676
671
return
677
672
}
678
673
Original file line number Diff line number Diff line change @@ -527,6 +527,40 @@ func TestZeroTimer(t *testing.T) {
527
527
}
528
528
}
529
529
530
+ // Test that rapidly moving a timer earlier doesn't cause it to get dropped.
531
+ // Issue 47329.
532
+ func TestTimerModifiedEarlier (t * testing.T ) {
533
+ past := Until (Unix (0 , 0 ))
534
+ count := 1000
535
+ fail := 0
536
+ for i := 0 ; i < count ; i ++ {
537
+ timer := NewTimer (Hour )
538
+ for j := 0 ; j < 10 ; j ++ {
539
+ if ! timer .Stop () {
540
+ <- timer .C
541
+ }
542
+ timer .Reset (past )
543
+ }
544
+
545
+ deadline := NewTimer (10 * Second )
546
+ defer deadline .Stop ()
547
+ now := Now ()
548
+ select {
549
+ case <- timer .C :
550
+ if since := Since (now ); since > 8 * Second {
551
+ t .Errorf ("timer took too long (%v)" , since )
552
+ fail ++
553
+ }
554
+ case <- deadline .C :
555
+ t .Error ("deadline expired" )
556
+ }
557
+ }
558
+
559
+ if fail > 0 {
560
+ t .Errorf ("%d failures" , fail )
561
+ }
562
+ }
563
+
530
564
// Benchmark timer latency when the thread that creates the timer is busy with
531
565
// other work and the timers must be serviced by other threads.
532
566
// https://golang.org/issue/38860
You can’t perform that action at this time.
0 commit comments