Skip to content

Commit dbcc7a2

Browse files
authored
Merge branch 'master' into sec-best-practice
2 parents 7926a32 + 3d0b4fa commit dbcc7a2

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

caddy.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,23 @@ func run(newCfg *Config, start bool) (Context, error) {
408408
return ctx, nil
409409
}
410410

411+
defer func() {
412+
// if newCfg fails to start completely, clean up the already provisioned modules
413+
// partially copied from provisionContext
414+
if err != nil {
415+
globalMetrics.configSuccess.Set(0)
416+
ctx.cfg.cancelFunc()
417+
418+
if currentCtx.cfg != nil {
419+
certmagic.Default.Storage = currentCtx.cfg.storage
420+
}
421+
}
422+
}()
423+
411424
// Provision any admin routers which may need to access
412425
// some of the other apps at runtime
413426
err = ctx.cfg.Admin.provisionAdminRouters(ctx)
414427
if err != nil {
415-
globalMetrics.configSuccess.Set(0)
416428
return ctx, err
417429
}
418430

@@ -438,7 +450,6 @@ func run(newCfg *Config, start bool) (Context, error) {
438450
return nil
439451
}()
440452
if err != nil {
441-
globalMetrics.configSuccess.Set(0)
442453
return ctx, err
443454
}
444455
globalMetrics.configSuccess.Set(1)
@@ -449,7 +460,8 @@ func run(newCfg *Config, start bool) (Context, error) {
449460

450461
// now that the user's config is running, finish setting up anything else,
451462
// such as remote admin endpoint, config loader, etc.
452-
return ctx, finishSettingUp(ctx, ctx.cfg)
463+
err = finishSettingUp(ctx, ctx.cfg)
464+
return ctx, err
453465
}
454466

455467
// provisionContext creates a new context from the given configuration and provisions

0 commit comments

Comments
 (0)