Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 13, 14:15 UTC
admin: Don't stop old server if new one fails (#4964)
Fixes #4954 Co-authored-by: Matthew Holt <mholt@users.noreply.github.com>
WeidiDeng committed
Aug 26, 2022 at 12:17 UTC
4c282e86dae16359370f410e29dc96dc5aeeb449
1 file changed
+4
-2
admin.go
+4
-2
@@ -340,17 +340,19 @@ func (admin AdminConfig) allowedOrigins(addr NetworkAddress) []*url.URL {
340
// that there is always an admin server (unless it is explicitly
341
// configured to be disabled).
342
func replaceLocalAdminServer(cfg *Config) error {
343
- // always be sure to close down the old admin endpoint
343
+ // always* be sure to close down the old admin endpoint
344
// as gracefully as possible, even if the new one is
345
// disabled -- careful to use reference to the current
346
// (old) admin endpoint since it will be different
347
// when the function returns
348
+ // (* except if the new one fails to start)
349
oldAdminServer := localAdminServer
350
+ var err error
351
defer func() {
352
// do the shutdown asynchronously so that any
353
// current API request gets a response; this
354
// goroutine may last a few seconds
353
- if oldAdminServer != nil {
355
+ if oldAdminServer != nil && err == nil {
356
go func(oldAdminServer *http.Server) {
357
err := stopAdminServer(oldAdminServer)
358
if err != nil {