Skip to content

Commit

Permalink
kvserver, timeutil: fix some Timer user-after-Stops
Browse files Browse the repository at this point in the history
Two guys were continuing to use a Timer after Stop()ing it, which is
illegal.

Release note: None
Release justification: Bug fix.
  • Loading branch information
andreimatei committed Mar 3, 2021
1 parent 50641ee commit 1512a14
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions pkg/kv/kvserver/closedts/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,17 @@ func (p *Provider) runCloser(ctx context.Context) {
// Track whether we've ever been live to avoid logging warnings about not
// being live during node startup.
var everBeenLive bool
var t timeutil.Timer
t := timeutil.NewTimer()
defer t.Stop()
for {
closeFraction := closedts.CloseFraction.Get(&p.cfg.Settings.SV)
targetDuration := float64(closedts.TargetDuration.Get(&p.cfg.Settings.SV))
if targetDuration > 0 {
t.Reset(time.Duration(closeFraction * targetDuration))
} else {
t.Stop() // disable closing when the target duration is non-positive
// Disable closing when the target duration is non-positive.
t.Stop()
t = timeutil.NewTimer()
}
select {
case <-p.cfg.Stopper.ShouldQuiesce():
Expand Down
5 changes: 3 additions & 2 deletions pkg/kv/kvserver/closedts/sidetransport/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,16 @@ func (s *Sender) Run(ctx context.Context, nodeID roachpb.NodeID) {
s.buf.Close()
}()

var timer timeutil.Timer
timer := timeutil.NewTimer()
defer timer.Stop()
for {
interval := closedts.SideTransportCloseInterval.Get(&s.st.SV)
if interval > 0 {
timer.Reset(closedts.SideTransportCloseInterval.Get(&s.st.SV))
timer.Reset(interval)
} else {
// Disable the side-transport.
timer.Stop()
timer = timeutil.NewTimer()
}
select {
case <-timer.C:
Expand Down

0 comments on commit 1512a14

Please sign in to comment.