mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 02:33:14 -04:00
fix: prevent SIGTERM/reload deadlock (#7562)
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user