diff options
author | WeidiDeng <[email protected]> | 2022-08-26 12:17:52 +0800 |
---|---|---|
committer | GitHub <[email protected]> | 2022-08-25 22:17:52 -0600 |
commit | 4c282e86dae16359370f410e29dc96dc5aeeb449 (patch) | |
tree | f8b27acbf50f04fafef18db58e825861d450e54c /admin.go | |
parent | 5fb5b81439a521294a88cf4ad6da49fdc350f3aa (diff) | |
download | caddy-4c282e86dae16359370f410e29dc96dc5aeeb449.tar.gz caddy-4c282e86dae16359370f410e29dc96dc5aeeb449.zip |
admin: Don't stop old server if new one fails (#4964)
Fixes #4954
Co-authored-by: Matthew Holt <[email protected]>
Diffstat (limited to 'admin.go')
-rw-r--r-- | admin.go | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -340,17 +340,19 @@ func (admin AdminConfig) allowedOrigins(addr NetworkAddress) []*url.URL { // that there is always an admin server (unless it is explicitly // configured to be disabled). func replaceLocalAdminServer(cfg *Config) error { - // always be sure to close down the old admin endpoint + // always* be sure to close down the old admin endpoint // as gracefully as possible, even if the new one is // disabled -- careful to use reference to the current // (old) admin endpoint since it will be different // when the function returns + // (* except if the new one fails to start) oldAdminServer := localAdminServer + var err error defer func() { // do the shutdown asynchronously so that any // current API request gets a response; this // goroutine may last a few seconds - if oldAdminServer != nil { + if oldAdminServer != nil && err == nil { go func(oldAdminServer *http.Server) { err := stopAdminServer(oldAdminServer) if err != nil { |