Skip to content

Commit

Permalink
Stopped timer can cause certificate to never update (#350)
Browse files Browse the repository at this point in the history
Once the `time.NewTimer()` expires, calls to `timer.Stop()` will return
`false`, but the channel will have nothing in it, causing `<-timer.C` to
hang forever.

This is hinted at by the docs, even though they suggest `timer.Stop()`
should return true in that case.

We change to a non-blocking drain so that we won't block forever.

This manifests in never updating the certificate after it expires,
causing TLS handshake errors.

Fixes #275
  • Loading branch information
Christopher Swenson authored May 23, 2022
1 parent 15a80ff commit 0288885
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion subcommand/injector/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,11 @@ func (c *Command) certWatcher(ctx context.Context, ch <-chan cert.Bundle, client

// clear the timer
if !timer.Stop() {
<-timer.C
// non-blocking drain
select {
case <-timer.C:
default:
}
}

err := c.updateCertificate(ctx, clientset, bundle, webhooksCache, leaderElector, log)
Expand Down

0 comments on commit 0288885

Please sign in to comment.