{"record":{"id":"a3dff2272e064e85","repo":"gofr-dev/gofr","slug":"w-got-d-a3dff2","errorCode":null,"errorMessage":"%w, got: %d","messagePattern":"%w, got: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/service/connection_pool.go","lineNumber":57,"sourceCode":"\t// MaxIdleConnsPerHost controls the maximum idle (keep-alive) connections to keep per-host.\n\t// This is the critical setting for microservices making frequent requests to the same host.\n\t// If set to 0, Go's DefaultMaxIdleConnsPerHost (2) will be used.\n\t// Negative values will cause validation error.\n\t// Default Go value: 2 (which is often insufficient for microservices)\n\t// Recommended: 10-20 for typical microservices, higher for high-traffic services\n\tMaxIdleConnsPerHost int\n\n\t// IdleConnTimeout is the maximum amount of time an idle (keep-alive) connection will remain\n\t// idle before closing itself.\n\t// If not explicitly set (0), a default of 90 seconds will be used.\n\t// Negative values will cause validation error.\n\tIdleConnTimeout time.Duration\n}\n\n// Validate checks if the connection pool configuration values are valid.\nfunc (c *ConnectionPoolConfig) Validate() error {\n\tif c.MaxIdleConns < 0 {\n\t\treturn fmt.Errorf(\"%w, got: %d\", errNegativeMaxIdleConns, c.MaxIdleConns)\n\t}\n\n\tif c.MaxIdleConnsPerHost < 0 {\n\t\treturn fmt.Errorf(\"%w, got: %d\", errNegativeMaxIdleConnsPerHost, c.MaxIdleConnsPerHost)\n\t}\n\n\tif c.IdleConnTimeout < 0 {\n\t\treturn fmt.Errorf(\"%w, got: %v\", errNegativeIdleConnTimeout, c.IdleConnTimeout)\n\t}\n\n\treturn nil\n}\n\n// AddOption implements the Options interface to apply connection pool configuration to HTTP service.\n// It modifies the underlying HTTP client's transport to use optimized connection pool settings.\nfunc (c *ConnectionPoolConfig) AddOption(h HTTP) HTTP {\n\t// Extract the base httpService from any wrapped service\n\thttpSvc := extractHTTPService(h)","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/service/connection_pool.go#L39-L75","documentation":"This is the wrapped form of errNegativeMaxIdleConns produced by (*ConnectionPoolConfig).Validate: fmt.Errorf(\"%w, got: %d\", ...) so the sentinel remains checkable with errors.Is while including the offending MaxIdleConns value. It fires before the pool settings are applied to the HTTP transport.","triggerScenarios":"Validate() (invoked directly or through AddOption when configuring AddHTTPService) sees c.MaxIdleConns < 0 and returns this wrapped error, e.g. ConnectionPoolConfig{MaxIdleConns: -5}.Validate().","commonSituations":"Environment-driven sizing producing negative numbers; negative values in YAML/JSON service config; arithmetic like maxConns - overhead underflowing to negative.","solutions":["Correct the config value so MaxIdleConns >= 0","Clamp with max(0, v) before constructing ConnectionPoolConfig","Call Validate() right after loading config to fail fast at startup","Match with errors.Is(err, errNegativeMaxIdleConns) for precise field-level error messages"],"exampleFix":"// before\nif err := pool.Validate(); err != nil { return err } // MaxIdleConns: -10\n// after\npool.MaxIdleConns = max(pool.MaxIdleConns, 0)\nif err := pool.Validate(); err != nil { return fmt.Errorf(\"invalid pool config: %w\", err) }","handlingStrategy":"validation","validationCode":"pool := &ConnectionPoolConfig{MaxIdleConns: v}\nif err := pool.Validate(); err != nil {\n    if errors.Is(err, errNegativeMaxIdleConns) {\n        return fmt.Errorf(\"config: MaxIdleConns invalid: %w\", err)\n    }\n    return err\n}","typeGuard":"func isNegativeMaxIdleConnsErr(err error) bool { return errors.Is(err, errNegativeMaxIdleConns) }","tryCatchPattern":"if err := pool.Validate(); err != nil {\n    if isNegativeMaxIdleConnsErr(err) {\n        return fallbackWithDefaults()\n    }\n    return fmt.Errorf(\"connection pool config: %w\", err)\n}","preventionTips":["Validate the whole ConnectionPoolConfig right after unmarshalling config","Clamp all int fields with max(0, value) when sourced from env/flags","Keep a table-test asserting negative inputs produce the expected sentinel errors","Log the offending value from the wrapped error message ('got: %d') in diagnostics"],"tags":["http-client","configuration","connection-pool","validation"],"backgroundTag":"invalid-config-value","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}