cmd: Promote undo maxProcs func to caller

This commit is contained in:
Matthew Holt committed 2025-03-06 16:47:02 -07:00
1 parent a686f7c346
commit 19876208c7
2 files changed
+6 -4

No files matched your search

+2 -1
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")
+4 -3
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.