I'm building currently a service that uses acme/autocert. To use that service with more than 1 replicas, I had to write a persistent cache interface like DirCache. Then I noticed, that after restarting the service all valid certs in the Cache got ignored on the startup. The following sequence happens all the time:
Is this the correct behavior? Because every replica would create its own cert and a persistent Cache is not possible with this circumstances
Here is my manager factory
func NewManager(d *db.DynamoDB, staging bool) *Manager {
manager := &Manager{
CertCache: NewPersistentCertCache(d),
}
directoryURL := acme.LetsEncryptURL
if staging {
directoryURL = LetsEncryptStagingURL
log.Infof("Using CA staging environment")
}
log.Infof("CA URI %s", directoryURL)
client := &acme.Client{
DirectoryURL: directoryURL,
}
manager.AcmeManager = &autocert.Manager{
Prompt: autocert.AcceptTOS,
HostPolicy: manager.AllowHostPolicy,
Cache: manager.CertCache,
Client: client,
}
return manager
}
The solution for this question is that the cache interface and behavior works correctly. My cache implementation was faulty. I had a goroutine within the Cache.Get(...) that read from a DB to a channel, but unfortunately the outer func body did not wait for that channel and returns always a CacheMissed error. After the fix everything works fine. My fault sry
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With