code: func (le *LeaderElector) renew(ctx context.Context) {
  	ctx, cancel := context.WithCancel(ctx)
  	defer cancel()
  	wait.Until(func() {
  		timeoutCtx, timeoutCancel := context.WithTimeout(ctx, le.config.RenewDeadline)
  		defer timeoutCancel()
  		err := wait.PollImmediateUntil(le.config.RetryPeriod, func() (bool, error) {
  			done := make(chan bool, 1)
  			go func() {
  				defer close(done)
  				done <- le.tryAcquireOrRenew()
  			}()
  
  			select {
  			case <-timeoutCtx.Done():
  				return false, fmt.Errorf("failed to tryAcquireOrRenew %s", timeoutCtx.Err())
  			case result := <-done:
  				return result, nil
  			}
  		}, timeoutCtx.Done())
  
  		le.maybeReportTransition()
  		desc := le.config.Lock.Describe()
  		if err == nil {
  			klog.V(5).Infof("successfully renewed lease %v", desc)
  			return
  		}
  		le.config.Lock.RecordEvent("stopped leading")
  		le.metrics.leaderOff(le.config.Name)
  		klog.Infof("failed to renew lease %v: %v", desc, err)
  		cancel()
  	}, le.config.RetryPeriod, ctx.Done())
  
  	// if we hold the lease, give it up
  	if le.config.ReleaseOnCancel {
  		le.release()
  	}
  }
docs: // renew loops calling tryAcquireOrRenew and returns immediately when tryAcquireOrRenew fails or ctx signals done.