Skip to content

Commit

Permalink
fix: double close chan on TLS challenge
Browse files Browse the repository at this point in the history
Co-authored-by: Julien Salleyron <[email protected]>
  • Loading branch information
ldez and juliens authored Mar 8, 2021
1 parent 3c8675b commit 09d5f59
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions pkg/provider/acme/challenge_tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,24 @@ func (c *ChallengeTLSALPN) Present(domain, _, keyAuth string) error {

timer := time.NewTimer(c.Timeout)

var errC error
select {
case t := <-timer.C:
timer.Stop()
close(c.chans[string(certPEMBlock)])

c.muChans.Lock()
c.cleanChan(string(certPEMBlock))
c.muChans.Unlock()

err = c.CleanUp(domain, "", keyAuth)
if err != nil {
logger.Errorf("Failed to clean up TLS challenge: %v", err)
}

errC = fmt.Errorf("timeout %s", t)
return fmt.Errorf("timeout %s", t)
case <-ch:
// noop
return nil
}

c.muChans.Lock()
delete(c.chans, string(certPEMBlock))
c.muChans.Unlock()

return errC
}

// CleanUp cleans the challenges when certificate is obtained.
Expand Down Expand Up @@ -115,16 +112,23 @@ func (c *ChallengeTLSALPN) Provide(configurationChan chan<- dynamic.Message, _ *

// ListenConfiguration sets a new Configuration into the configurationChan.
func (c *ChallengeTLSALPN) ListenConfiguration(conf dynamic.Configuration) {
c.muChans.Lock()

for _, certificate := range conf.TLS.Certificates {
if !containsACMETLS1(certificate.Stores) {
continue
}

c.muChans.Lock()
if _, ok := c.chans[certificate.CertFile.String()]; ok {
close(c.chans[certificate.CertFile.String()])
}
c.muChans.Unlock()
c.cleanChan(certificate.CertFile.String())
}

c.muChans.Unlock()
}

func (c *ChallengeTLSALPN) cleanChan(key string) {
if _, ok := c.chans[key]; ok {
close(c.chans[key])
delete(c.chans, key)
}
}

Expand Down

0 comments on commit 09d5f59

Please sign in to comment.