fix: fix reload causing secondary plugin goroutine to leak. (#7694)

Signed-off-by: wenxuan70 <t736660416@gmail.com>
This commit is contained in:
wenxuan70
2025-11-20 09:17:57 +08:00
committed by GitHub
parent 9989ac5060
commit e56971b253
2 changed files with 20 additions and 2 deletions

View File

@@ -27,6 +27,9 @@ func setup(c *caddy.Controller) error {
n := zones.Names[i]
z := zones.Z[n]
if len(z.TransferFrom) > 0 {
// In order to support secondary plugin reloading.
updateShutdown := make(chan bool)
c.OnStartup(func() error {
z.StartupOnce.Do(func() {
go func() {
@@ -43,12 +46,21 @@ func setup(c *caddy.Controller) error {
if dur > max {
dur = max
}
select {
case <-updateShutdown:
return
default:
}
}
z.Update()
z.Update(updateShutdown)
}()
})
return nil
})
c.OnShutdown(func() error {
updateShutdown <- true
return nil
})
}
}