mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-16 21:56:40 -05:00
caddytls: Fix goroutine leak when restarting Caddy (#2644)
Each time the Caddyfile reloads and Caddy is restarted, caddytls.NewConfig starts a goroutine for cleaning the certificate storage. This goroutine ranges over a time.Ticker channel; although Stop is called on this ticker, Stop does not close the underlying channel so the goroutine never exits. This change adds an additional channel that is listened to in the certificate cleaning goroutine so it can exit on restarts.
This commit is contained in:
parent
14a8ffedd8
commit
d11b648137
1 changed files with 14 additions and 5 deletions
|
@ -140,17 +140,26 @@ func NewConfig(inst *caddy.Instance) (*Config, error) {
|
|||
return certmagic.Default, nil
|
||||
},
|
||||
})
|
||||
|
||||
storageCleaningTicker := time.NewTicker(12 * time.Hour)
|
||||
done := make(chan bool)
|
||||
go func() {
|
||||
for range storageCleaningTicker.C {
|
||||
certmagic.CleanStorage(certmagic.Default.Storage, certmagic.CleanStorageOptions{
|
||||
OCSPStaples: true,
|
||||
})
|
||||
for {
|
||||
select {
|
||||
case <-done:
|
||||
storageCleaningTicker.Stop()
|
||||
return
|
||||
case <-storageCleaningTicker.C:
|
||||
certmagic.CleanStorage(certmagic.Default.Storage, certmagic.CleanStorageOptions{
|
||||
OCSPStaples: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
}()
|
||||
inst.OnShutdown = append(inst.OnShutdown, func() error {
|
||||
certCache.Stop()
|
||||
storageCleaningTicker.Stop()
|
||||
done <- true
|
||||
close(done)
|
||||
return nil
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue