fix: prevent SIGTERM/reload deadlock (#7562)

This commit is contained in:
Ville Vesilehto
2025-09-19 14:01:53 +03:00
committed by GitHub
parent 5532ba8484
commit 6ec327836b
6 changed files with 171 additions and 24 deletions

View File

@@ -105,6 +105,10 @@ func hook(event caddy.EventName, info any) error {
// now lets consider that plugin will not be reload, unless appear in next config file
// change status of usage will be reset in setup if the plugin appears in config file
r.setUsage(maybeUsed)
// If shutdown is in progress, avoid attempting a restart.
if shutdownRequested(r.quit) {
return
}
_, err := instance.Restart(corefile)
reloadInfo.WithLabelValues("sha512", hex.EncodeToString(sha512sum[:])).Set(1)
if err != nil {
@@ -126,3 +130,14 @@ func hook(event caddy.EventName, info any) error {
return nil
}
// shutdownRequested reports whether a shutdown has been requested via quit channel.
// helps with unit testing of the shutdown gate logic.
func shutdownRequested(quit <-chan bool) bool {
select {
case <-quit:
return true
default:
return false
}
}