autocert: fix locking issue (#1310) (#1311)

This commit is contained in:
Caleb Doxsey 2020-08-20 14:43:51 -06:00 committed by GitHub
parent b521ccc5e2
commit 9efeabd956
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,7 @@ import (
"net/http" "net/http"
"sort" "sort"
"sync" "sync"
"sync/atomic"
"github.com/caddyserver/certmagic" "github.com/caddyserver/certmagic"
@ -22,7 +23,7 @@ type Manager struct {
mu sync.RWMutex mu sync.RWMutex
config *config.Config config *config.Config
certmagic *certmagic.Config certmagic *certmagic.Config
acmeMgr *certmagic.ACMEManager acmeMgr atomic.Value
srv *http.Server srv *http.Server
config.ChangeDispatcher config.ChangeDispatcher
@ -74,7 +75,7 @@ func (mgr *Manager) getCertMagicConfig(options *config.Options) (*certmagic.Conf
} }
acmeMgr.DisableTLSALPNChallenge = true acmeMgr.DisableTLSALPNChallenge = true
mgr.certmagic.Issuer = acmeMgr mgr.certmagic.Issuer = acmeMgr
mgr.acmeMgr = acmeMgr mgr.acmeMgr.Store(acmeMgr)
return mgr.certmagic, nil return mgr.certmagic, nil
} }
@ -166,9 +167,7 @@ func (mgr *Manager) updateServer(cfg *config.Config) {
} }
func (mgr *Manager) handleHTTPChallenge(w http.ResponseWriter, r *http.Request) bool { func (mgr *Manager) handleHTTPChallenge(w http.ResponseWriter, r *http.Request) bool {
mgr.mu.RLock() acmeMgr := mgr.acmeMgr.Load().(*certmagic.ACMEManager)
acmeMgr := mgr.acmeMgr
mgr.mu.RUnlock()
if acmeMgr == nil { if acmeMgr == nil {
return false return false
} }