From 34cff4af7db1365bba6decc647ccfb6bf1b21afd Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 31 Dec 2024 13:08:58 -0700 Subject: [PATCH] core: Only initiate exit once (should fix #6707) --- caddy.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/caddy.go b/caddy.go index b3e8889fa..758b0b2f6 100644 --- a/caddy.go +++ b/caddy.go @@ -725,8 +725,10 @@ func Validate(cfg *Config) error { // Errors are logged along the way, and an appropriate exit // code is emitted. func exitProcess(ctx context.Context, logger *zap.Logger) { - // let the rest of the program know we're quitting - atomic.StoreInt32(exiting, 1) + // let the rest of the program know we're quitting; only do it once + if !atomic.CompareAndSwapInt32(exiting, 0, 1) { + return + } // give the OS or service/process manager our 2 weeks' notice: we quit if err := notify.Stopping(); err != nil {