diff --git a/manager/dispatcher/dispatcher.go b/manager/dispatcher/dispatcher.go index 407ced0b69..da91ff5e9e 100644 --- a/manager/dispatcher/dispatcher.go +++ b/manager/dispatcher/dispatcher.go @@ -293,9 +293,16 @@ func (d *Dispatcher) Run(ctx context.Context) error { publishManagers(ev.([]*api.Peer)) case <-d.processUpdatesTrigger: d.processUpdates(ctx) + batchTimer.Stop() + // drain the timer, if it has already expired + select { + case <-batchTimer.C: + default: + } batchTimer.Reset(maxBatchInterval) case <-batchTimer.C: d.processUpdates(ctx) + // batch timer has already expired, so no need to drain batchTimer.Reset(maxBatchInterval) case v := <-configWatcher: cluster := v.(api.EventUpdateCluster) diff --git a/node/node.go b/node/node.go index 98283f936f..83187cc75b 100644 --- a/node/node.go +++ b/node/node.go @@ -1136,6 +1136,11 @@ func (n *Node) superviseManager(ctx context.Context, securityConfig *ca.Security // re-promoted. In this case, we must assume we were // re-promoted, and restart the manager. log.G(ctx).Warn("failed to get worker role after manager stop, forcing certificate renewal") + + // We can safely reset this timer without stopping/draining the timer + // first because the only way the code has reached this point is if the timer + // has already expired - if the role changed or the context were canceled, + // then we would have returned already. timer.Reset(roleChangeTimeout) renewer.Renew()