cmd: Promote undo maxProcs func to caller

This commit is contained in:
Matthew Holt 2025-03-06 16:47:02 -07:00
parent a686f7c346
commit 19876208c7
No known key found for this signature in database
GPG Key ID: 2A349DD577D586A5
2 changed files with 6 additions and 4 deletions

View File

@ -172,7 +172,8 @@ func cmdRun(fl Flags) (int, error) {
caddy.TrapSignals()
logger := caddy.Log()
setResourceLimits(logger)
undoMaxProcs := setResourceLimits(logger)
defer undoMaxProcs()
configFlag := fl.String("config")
configAdapterFlag := fl.String("adapter")

View File

@ -464,13 +464,12 @@ func printEnvironment() {
}
}
func setResourceLimits(logger *zap.Logger) {
func setResourceLimits(logger *zap.Logger) func() {
// Configure the maximum number of CPUs to use to match the Linux container quota (if any)
// See https://pkg.go.dev/runtime#GOMAXPROCS
undo, err := maxprocs.Set(maxprocs.Logger(logger.Sugar().Infof))
defer undo()
if err != nil {
caddy.Log().Warn("failed to set GOMAXPROCS", zap.Error(err))
logger.Warn("failed to set GOMAXPROCS", zap.Error(err))
}
// 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) {
),
),
)
return undo
}
// StringSlice is a flag.Value that enables repeated use of a string flag.