mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-31 10:19:44 +08:00 
			
		
		
		
	cmd: Promote undo maxProcs func to caller
This commit is contained in:
		| @ -172,7 +172,8 @@ func cmdRun(fl Flags) (int, error) { | |||||||
| 	caddy.TrapSignals() | 	caddy.TrapSignals() | ||||||
|  |  | ||||||
| 	logger := caddy.Log() | 	logger := caddy.Log() | ||||||
| 	setResourceLimits(logger) | 	undoMaxProcs := setResourceLimits(logger) | ||||||
|  | 	defer undoMaxProcs() | ||||||
|  |  | ||||||
| 	configFlag := fl.String("config") | 	configFlag := fl.String("config") | ||||||
| 	configAdapterFlag := fl.String("adapter") | 	configAdapterFlag := fl.String("adapter") | ||||||
|  | |||||||
| @ -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) | 	// Configure the maximum number of CPUs to use to match the Linux container quota (if any) | ||||||
| 	// See https://pkg.go.dev/runtime#GOMAXPROCS | 	// See https://pkg.go.dev/runtime#GOMAXPROCS | ||||||
| 	undo, err := maxprocs.Set(maxprocs.Logger(logger.Sugar().Infof)) | 	undo, err := maxprocs.Set(maxprocs.Logger(logger.Sugar().Infof)) | ||||||
| 	defer undo() |  | ||||||
| 	if err != nil { | 	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 | 	// 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. | // StringSlice is a flag.Value that enables repeated use of a string flag. | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Matthew Holt
					Matthew Holt