From c8514ad7b7329f348a3a9a9d9490a99f59847a9e Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Mon, 6 Mar 2017 19:20:13 -0700 Subject: [PATCH] Avoid panic if reloading before server is started See: https://forum.caddyserver.com/t/reloading-template-files-as-they-change/1483/3?u=matt The server takes a moment to start; if USR1 is received before the instance is saved, it would panic because no instances have been saved. Instead, we just ignore the signal since no config has finished loading. --- sigtrap_posix.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sigtrap_posix.go b/sigtrap_posix.go index 9ee7bbba..e046bee9 100644 --- a/sigtrap_posix.go +++ b/sigtrap_posix.go @@ -49,8 +49,14 @@ func trapSignalsPosix() { // Start with the existing Caddyfile instancesMu.Lock() + if len(instances) == 0 { + instancesMu.Unlock() + log.Println("[ERROR] SIGUSR1: No server instances are fully running") + continue + } inst := instances[0] // we only support one instance at this time instancesMu.Unlock() + updatedCaddyfile := inst.caddyfileInput if updatedCaddyfile == nil { // Hmm, did spawing process forget to close stdin? Anyhow, this is unusual.