mirror of
https://github.com/caddyserver/caddy.git
synced 2025-10-19 07:43:17 +00:00
tls: wait for keeping storage clean to finish when stopping
This commit is contained in:
parent
4bfc3b95b5
commit
d5b7c74c88
1 changed files with 15 additions and 7 deletions
|
@ -130,6 +130,7 @@ type TLS struct {
|
|||
ctx caddy.Context
|
||||
storageCleanTicker *time.Ticker
|
||||
storageCleanStop chan struct{}
|
||||
storageCleanStopDone chan struct{}
|
||||
logger *zap.Logger
|
||||
events *caddyevents.App
|
||||
|
||||
|
@ -439,6 +440,9 @@ func (t *TLS) Stop() error {
|
|||
if t.storageCleanTicker != nil {
|
||||
t.storageCleanTicker.Stop()
|
||||
}
|
||||
if t.storageCleanStopDone != nil {
|
||||
<-t.storageCleanStopDone
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -788,16 +792,20 @@ func (t *TLS) HasCertificateForSubject(subject string) bool {
|
|||
func (t *TLS) keepStorageClean() {
|
||||
t.storageCleanTicker = time.NewTicker(t.storageCleanInterval())
|
||||
t.storageCleanStop = make(chan struct{})
|
||||
t.storageCleanStopDone = make(chan struct{})
|
||||
go func() {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
log.Printf("[PANIC] storage cleaner: %v\n%s", err, debug.Stack())
|
||||
// close the channel manually if panicked
|
||||
close(t.storageCleanStopDone)
|
||||
}
|
||||
}()
|
||||
t.cleanStorageUnits()
|
||||
for {
|
||||
select {
|
||||
case <-t.storageCleanStop:
|
||||
close(t.storageCleanStopDone)
|
||||
return
|
||||
case <-t.storageCleanTicker.C:
|
||||
t.cleanStorageUnits()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue