caddytls: Mark storage clean timestamp at end of routine (#4401)

See discussion on 42b7134ffa
This commit is contained in:
Matt Holt 2021-11-02 08:27:25 -06:00 committed by GitHub
parent 3385856966
commit 24fda7514d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -458,20 +458,17 @@ func (t *TLS) cleanStorageUnits() {
defer storageCleanMu.Unlock() defer storageCleanMu.Unlock()
// If storage was cleaned recently, don't do it again for now. Although the ticker // If storage was cleaned recently, don't do it again for now. Although the ticker
// drops missed ticks for us, config reloads discard the old ticker and replace it // calling this function drops missed ticks for us, config reloads discard the old
// with a new one, possibly invoking a cleaning to happen again too soon. // ticker and replace it with a new one, possibly invoking a cleaning to happen again
// (We divide the interval by 2 because the actual cleaning takes non-zero time, // too soon. (We divide the interval by 2 because the actual cleaning takes non-zero
// and we don't want to skip cleanings if we don't have to; whereas if a cleaning // time, and we don't want to skip cleanings if we don't have to; whereas if a cleaning
// took the entire interval, we'd probably want to skip the next one so we aren't // took most of the interval, we'd probably want to skip the next one so we aren't
// constantly cleaning. This allows cleanings to take up to half the interval's // constantly cleaning. This allows cleanings to take up to half the interval's
// duration before we decide to skip the next one.) // duration before we decide to skip the next one.)
if !storageClean.IsZero() && time.Since(storageClean) < t.storageCleanInterval()/2 { if !storageClean.IsZero() && time.Since(storageClean) < t.storageCleanInterval()/2 {
return return
} }
// mark when storage cleaning was last initiated
storageClean = time.Now()
options := certmagic.CleanStorageOptions{ options := certmagic.CleanStorageOptions{
OCSPStaples: true, OCSPStaples: true,
ExpiredCerts: true, ExpiredCerts: true,
@ -504,6 +501,9 @@ func (t *TLS) cleanStorageUnits() {
} }
} }
// remember last time storage was finished cleaning
storageClean = time.Now()
t.logger.Info("finished cleaning storage units") t.logger.Info("finished cleaning storage units")
} }