Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 12, 03:15 UTC
cmd: Promote undo maxProcs func to caller
Matthew Holt committed
Mar 6, 2025 at 16:47 UTC
19876208c79a476a46beec2430e554d4161ab426
2 files changed
+6
-4
cmd/commandfuncs.go
+2
-1
@@ -172,7 +172,8 @@ func cmdRun(fl Flags) (int, error) {
172
caddy.TrapSignals()
173
174
logger := caddy.Log()
175
- setResourceLimits(logger)
175
+ undoMaxProcs := setResourceLimits(logger)
176
+ defer undoMaxProcs()
177
178
configFlag := fl.String("config")
179
configAdapterFlag := fl.String("adapter")
cmd/main.go
+4
-3
@@ -464,13 +464,12 @@ func printEnvironment() {
464
}
465
}
466
467
-func setResourceLimits(logger *zap.Logger) {
467
+func setResourceLimits(logger *zap.Logger) func() {
468
// Configure the maximum number of CPUs to use to match the Linux container quota (if any)
469
// See https://pkg.go.dev/runtime#GOMAXPROCS
470
undo, err := maxprocs.Set(maxprocs.Logger(logger.Sugar().Infof))
471
- defer undo()
471
if err != nil {
473
- caddy.Log().Warn("failed to set GOMAXPROCS", zap.Error(err))
472
+ logger.Warn("failed to set GOMAXPROCS", zap.Error(err))
473
}
474
475
// Configure the maximum memory to use to match the Linux container quota (if any) or system memory
@@ -486,6 +485,8 @@ func setResourceLimits(logger *zap.Logger) {
485
),
486
),
487
)
488
+
489
+ return undo
490
}
491
492
// StringSlice is a flag.Value that enables repeated use of a string flag.